Last Updated: February 25, 2016
·
1.255K
· russellengland

Delete duplicate rows

Here's a quick and easy way to delete duplicate rows - make sure you have backed up, just in case!

First create a temporary table using DISTINCT

CREATE TABLE temptable
SELECT DISTINCT *
FROM originaltable;

Then empty the old table

TRUNCATE TABLE originaltable;

Then copy from the temporary table - this will ensure all the original table settings remain intact

INSERT INTO originaltable
SELECT * FROM temptable

1 Response
Add your response

Or just add unique index and all duplicate rows are deleted automatically.

ALTER IGNORE TABLE table1 ADD UNIQUE (field1, field2);
over 1 year ago ·