Tuesday, May 8, 2012

How to delete duplicate rows in single statement

Suppose we have a table named DuplicateData in which same row with Id and name exixts more than one.
then we have to delete those rows using this:

WITH T1 AS (Select Id,FirstName,LastName, ROW_NUMBER() OVER (PARTITION BY Id,FirstName,LastName Order By Id) AS NUMBER From DuplicateData )Delete From T1 Where Number >1 Go