Created
October 19, 2011 09:09
-
-
Save memphys/1297802 to your computer and use it in GitHub Desktop.
Deleting duplicates in MySQL 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
SELECT field, COUNT(field) AS total FROM table GROUP BY field HAVING (COUNT(field) > 1) | |
DELETE t1 FROM table t1, table t2 WHERE t1.field = t2.field AND t1.id > t2.id | |
ALTER IGNORE TABLE table ADD UNIQUE INDEX(table) | |
DELETE t1 FROM table as t1, table as t2 WHERE t1.x = t2.x AND t1.y = t2.y AND t1.id > t2.id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment