Archive for April, 2010

How to remove duplicate entries from a table ?

Posted by om 21 April, 2010 (0) Comment

Removing Duplicate entries from Mysql database table are really simple. I have found some times interviewer ask tricky questions like this. PHP-MYSQL Beginners  just be careful !

It can all be done with three manual SQL steps! No PHP Coding required, and it works with MySQL 4 and above versions.

Step One -

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

Step Two – You hate to keep old table with all the duplicate entries, so drop it!

DROP TABLE MyOldTable;
RENAME TABLE MyNewTable TO MyOldTable;
  • Share/Bookmark
Categories : Mysql Interview Tags :