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 -
View Code SQL
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!
View Code SQL
DROP TABLE MyOldTable; |
View Code SQL
RENAME TABLE MyNewTable TO MyOldTable; |
Categories : Mysql Interview

