Skip to content

Instantly share code, notes, and snippets.

@jcisio
Created January 23, 2013 08:35
Show Gist options
  • Save jcisio/4603181 to your computer and use it in GitHub Desktop.
Save jcisio/4603181 to your computer and use it in GitHub Desktop.
MySQL table deduplication
-- Deduplication on all rows
CREATE TEMPORARY TABLE bad_temp AS SELECT DISTINCT * FROM your_table;
DELETE FROM your_table;
INSERT INTO your_table SELECT * FROM bad_temp;
-- Deduplication on some rows
CREATE TEMPORARY TABLE bad_temp AS SELECT * FROM your_table GROUP BY field1, field2, field3;
DELETE FROM your_table;
INSERT INTO your_table SELECT * FROM bad_temp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment