Last active
May 24, 2016 20:17
-
-
Save ronmichael/5985156 to your computer and use it in GitHub Desktop.
Delete duplicate records in MSSQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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