I would like to delete rows from my database that have the same name. I’ve checked Stackoverflow and found something like this:
DELETE
FROM my_table mt1 USING my_table mt2
WHERE mt1.my_name = mt2.my_name AND mt1.unique_id<mt2.unique_id;
This of course works but leaves one row. I have a request:
If there are rows with duplicate rows I have to remove ALL of them (not leave one).
2
Answers
We can use
GROUP BY
with aHAVING
clause as subquery:Try out: db<>fiddle
See if you can use this as a template.