Last active
November 27, 2021 18:25
-
-
Save codez0mb1e/eb691183bd177300ac4e0c142b7406b0 to your computer and use it in GitHub Desktop.
Delete duplicates from table
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
WITH duplicates AS ( | |
SELECT | |
*, | |
ROW_NUMBER() OVER ( | |
PARTITION BY Id | |
ORDER BY [Timestamp] | |
) row_n | |
FROM | |
<table_name> -- NOTE: insert name of target table here | |
WHERE | |
DATEDIFF(month, [Timestamp], GETDATE()) = 1 | |
) | |
DELETE FROM duplicates | |
WHERE row_n > 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment