Hi,
I have a mysql table which has duplicated content. I want to delete all duplicated content, except leave one row. any suggestions?
[Resolved] deleting duplicated content from mysql, how?
Moderator: General Moderators
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
[Resolved] deleting duplicated content from mysql, how?
Last edited by kaisellgren on Mon Mar 19, 2007 12:33 pm, edited 1 time in total.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Write a query that orders all the duplicates together. Using an array to store the id's of records, iterate over the result set storing the id of each record which matches the previous record. When the newest record changes remove one of the id's (to keep) and delete the rest. After which you reset the array and start storing id's again. Wash, rinse, repeat.
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.