Skip to content

Instantly share code, notes, and snippets.

@ronmichael
Last active May 24, 2016 20:17
Show Gist options
  • Save ronmichael/5985156 to your computer and use it in GitHub Desktop.
Save ronmichael/5985156 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment