Removing duplicated rows from a MySQL table
May 17th 2011This tip is a simple query to remove duplicated entries from a MySQL table.
DELETE FROM table1
USING table1,
table1 as table2
WHERE table2.id > table1.id
AND table2.unique_param = table1.unique_param
Here I’m using a virtual copy of table1 to check whether it has uniq_param’s after the first ocurrence of the id, and then delete it.
It will only works if you have a sequencial ‘id’ column. You can do a select before really deleting to check if it will do the proper thing.




