Joomla TemplatesWeb HostingWeb Hosting

delete duplicate row

from http://www.justin-cook.com/wp/2006/12/12/remove-duplicate-entries-rows-a-mysql-database-table/

 

This is an extremely quick and painless way to remove duplicate rows (tuples) from a MySQL database table. The best part of it is that it requires no programming or PHP coding whatsoever, it can all be done with three manual SQL queries! Note: this only works on MySQL 3.23 and above. But I have a hard time imagining anyone running an older version than that anyways!

So, there are 3 steps, and therefore 3 SQL statements:

Step 1: Move the non duplicates (unique tuples) into a temporary table


CREATE TABLE new_table as
SELECT * FROM old_table WHERE 1 GROUP BY 

Step 2: delete delete the old table
We no longer need the table with all the duplicate entries, so drop it!


DROP TABLE old_table;

Step 3: rename the new_table to the name of the old_table


RENAME TABLE new_table TO old_table;

And of course, don't forget to fix your buggy code to stop inserting duplicates!


 
Joomla templates and extensions Your ad here Your ad here Your ad here Your ad here Your ad here Your ad here Your ad here
Hadith 23
Daripada Abu Malik al-Haris ibn `Asim al-Asya'arie r.a. beliau berkata: Rasulullah SAW telah bersabda:

Kebersihan itu sebahagian daripada iman. Ucapan zikir al-Hamdulillah memenuhi neraca timbangan. Ucapan zikir Subhaanallah dan al-Hamdulillah kedua-duanya memenuhi ruangan antara langit dan bumi. Sembahyang itu adalah cahaya. Sedekah itu adalah saksi. Sabar itu adalah sinaran. Al-Qur'an itu adalah hujah bagimu atau hujah ke atasmu. Setiap manusia keluar waktu pagi, ada yang menjual dirinya, ada yang memerdekakan dirinya dan ada pula yang mencelakakan dirinya.

Hadith riwayat Muslim.
AJ Article Listing
Galeri YouTube Terpilih