MySQL Remove Duplicates

A quick method to remove duplicate records from your database:

ALTER IGNORE TABLE tablename ADD UNIQUE INDEX dublicatedindex (fieldthatcontaindoubles);
ALTER TABLE tablename DROP INDEX dublicatedindex

The method above will remove dublicates and will add a Unique key to the field of interest.

Another non-recommended option is:

CREATE TABLE tablenamenew as SELECT * FROM acttable WHERE 1 GROUP BY fieldthatcontaindoubles;

The syntax will create a new table that has unique records on fieldthatcontaindoubles

Leave a Reply