I have table with 3 columns :
ID, name, role Some names are duplicated but they all have an unique ID, how do I delete all rows with duplicated name(not all,leave one for each) in my table?
Group by the name and select the lowest unique id. Delete all records that are not in that list
delete from your_table where id not in ( select min(id) from your_table group by name ) And if you use MySQL you need another subquery since MySQL does not allow you to delete from the same table you are selecting from:
delete from your_table where id not in ( select * from ( select min(id) from your_table group by name ) tmp_tbl )