Sai Stuff to Developers

June 23, 2010

Querry to Deleting Duplicate Records

Filed under: DataBase — tosaik @ 12:36 pm
Tags:

Hi,

  Many people will struct with their  work when comming to delete duplicate records in a table with single querry.
I want to make it easy your job by following Querry.

Note: this Querry works in Sql Server 7.0 and above versions
;WITH T
AS
(
SELECT *,ROW_NUMBER() OVER(PARTITION BY <Fieldname>  ORDER BY <PrimaryKeyFieldName>) AS RANK1 FROM <TableName>
) Delete  FROM T WHERE RANK1 > 1

Blog at WordPress.com.