Delete all duplicate records from a table

Public

Remove dupe rows

</> CopyGet raw version
sql
  1. -- Add an index on the table in question that is unique for some combination of fields.
  2. -- We're ignoring the warning that this will cause some rows to be dropped.
  3. ALTER IGNORE TABLE my_table ADD UNIQUE INDEX dupidx (field_1, field_2);
  4. -- The dupes are gone, remove the index.
  5. ALTER TABLE my_table DROP INDEX dupidx;