Created
September 24, 2012 14:40
-
-
Save Simcamb/3776272 to your computer and use it in GitHub Desktop.
Delete duplicates and keep the newest one in mySQL
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
DELETE mytable | |
FROM mytable | |
INNER JOIN ( | |
SELECT max(id) AS lastId, someColumnWithDupes | |
FROM mytable | |
GROUP BY someColumnWithDupes | |
HAVING count(*) > 1 | |
) duplic ON duplic.someColumnWithDupes = mytable.someColumnWithDupes | |
WHERE mytable.id < duplic.lastId; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment