Forked from davidsheardown/MSSQL_CTE_RemoveDuplicates.sql
Created
May 29, 2019 16:31
-
-
Save morbidcamel101/826f263a22719559a884dc32b69daa8d 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