MySQL/ASP – Delete Duplicate Rows
I have a table with 100,000 rows called ‘photoSearch’. When transferring the data from other tables (that took bloody ages and I was bloody tired), I accidentally forgot to remove the test transfer I did, which left 3500 rows in the table before I transferred everything over in one go.
The ID column is ‘photoID’ (INT) and I need to remove all duplicates that have a photoID of less than 6849. If I could just remove the duplicates, it would be less painful than to delete the table and start another transfer.
Has anybody got any suggestions on the most practical and safest way to do this?
UPDATE:
I actually answered my own question. I backed up my table for safety, and then I ran this:
ALTER IGNORE TABLE photoSearch ADD UNIQUE INDEX unique_id_index (photoID);
This removed all 3500 duplicates in under a minute 🙂
Traditional method
Backup your existing table
photoSearchto something liketmp_photoSearchusing aAfter that, you can perform data massage into table
tmp_photoSearch.Once you have gotten the results as expected,
perform a swap table
To increase insert speed (if the bottle-neck is not on network transfer),
http://dev.mysql.com/doc/refman/5.0/en/insert-speed.html