Deleting duplicate records using T-SQL

WITH cte AS (
SELECT [Field1], [Field2]
 row_number() OVER(PARTITION BY [Field1], [Field2] ORDER BY [Field1]) AS [rn]
 FROM [Table1] WHERE [Column1]=[Condition1]
 )
DELETE cte WHERE [rn] > 1

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.