ronmichael
7/12/2013 - 3:04 PM

Delete duplicate records in MSSQL

Delete duplicate records in MSSQL

/* thanks to http://stackoverflow.com/questions/18390574/how-to-delete-duplicate-rows-in-sql-server */
/* partition on the columns that make the row unique */

with dupes as (
   select *, rn = ROW_NUMBER() OVER (PARTITION BY col1, col2 ORDER BY col1)
   from sources
)
delete from dupes 
where rn > 1