Deleting duplicate rows in mysql
http://forums.mysql.com/read.php?47,255365,257894#msg-257894
consider employee table(number,name,salary) to contain your data
1 ethan 900
1 ethan 900
2 sumakar 800
3 jay 800
4 jack 700
4 jack 700
4 jack 700
Follow the three steps below,
Step 1: Move the non duplicates to a temporary table
CREATE TABLE new_employee AS
SELECT * FROM employee WHERE 1 GROUP BY number,name,salary;
Step 2: delete old table
We no longer need the table with all the duplicate entries, so drop it!
DROP TABLE employee;
Step 3: rename the new_table to the name of the old_table
RENAME TABLE new_employee TO employee;
If your table has indexes, hold on a minute…;)
————————————————————————————————
This worked like a charm. However I did it a sligthly different way, using Sequel Pro on Mac OSX:
1) Right-click the table on the sidebar and click “Duplicate Table”. Make sure that you check the box that says duplicate table. This could take a while with a large table, mine had about 67,000 rows.
2) Truncate the original table.
3) In the query window, use the query as stated above, but with an insert:
INSERT INTO table
SELECT * FROM tmp_table GROUP BY id, category
etc.