Skip to content

Instantly share code, notes, and snippets.

@memphys
Created October 19, 2011 09:09
Show Gist options
  • Save memphys/1297802 to your computer and use it in GitHub Desktop.
Save memphys/1297802 to your computer and use it in GitHub Desktop.
Deleting duplicates in MySQL table
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