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
Written by Russell England
Related protips
1 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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Mysql
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#