I need to remove all rows having duplicated title
column. Something like:
delete from clients where title is duplicated
For example, if five rows have the same title
column – four of them shold be deleted.
How to do this?
Advertisement
Answer
If you have a unique column like id
or somedate
:
delete c from clients c inner join clients cc on cc.title = c.title and cc.id < c.id
This code will keep the row with the minimum id among the duplicates.
See the demo.