YamdaBlam!

MySQL – Removing duplicate rows from a table

by on May.19, 2011, under MySQL

This save me loads of hassle this morning as I ran my script which populated an important table with duplicate entries which should not be there.

This is a must share for those who fall into the same problem.

Open up a mysql editor and paste in the following (don’t forget to edit for your table names)

CREATE TABLE new_table as
SELECT * FROM old_table WHERE 1 GROUP BY [column to remove duplicates by];

Drop the old table and rename the new one – job done!

Quick, easy and slightly painless.

:, ,
No comments for this entry yet...

Leave a Reply

Powered by WP Hashcash

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!