Created
May 3, 2017 09:55
-
-
Save davidsheardown/781374d7e00f587e88aac942caf609e2 to your computer and use it in GitHub Desktop.
MS SQL (CTE) Remove Duplicate Rows
This file contains 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
;WITH CTE AS( | |
SELECT field_to_identify_duplicate, | |
RN = ROW_NUMBER()OVER(PARTITION BY field_to_identify_duplicate ORDER BY field_to_identify_duplicate) | |
FROM table_with_duplicates | |
) | |
DELETE FROM CTE WHERE RN > 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment