Last active
March 27, 2023 11:41
-
-
Save mikehins/70ea21be21b00e1784971b6ee6d2708b to your computer and use it in GitHub Desktop.
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
# https://sqlfordevs.com/delete-duplicate-rows | |
WITH duplicates AS ( | |
SELECT id, ROW_NUMBER() OVER | |
( | |
PARTITION BY firstname, lastname, email | |
ORDER BY age DESC | |
) AS rownum | |
FROM contacts | |
) | |
DELETE contacts | |
FROM | |
contacts | |
JOIN duplicates USING ( id ) | |
WHERE | |
duplicates. rownum > 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment