Last active
July 21, 2022 16:03
-
-
Save mikehins/fbb83311dd000f5e10ee0b60fcc6eda7 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.io/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