How do I delete rows having duplicate data.Of course one row should be there remaining.I was asked to do this with a Delete query and using limit clause.But I am clueless.
Any help?
Delete duplicate rows
Moderator: General Moderators
The following code will delete everything 5 times. Meaning, that if you have 10 rows of duplicates, 5 of them will go away. If you have 2 rows of duplicates, all of them will go away (perhaps even generate an error).
Don't know if that helped, but if you only have 2 rows of duplicates for each 'thing' a limit setting of 1 would do the trick.
Code: Select all
delete from table_name where foo = 'bar' limit 5