--!sql -- table people id | name ----+------ 1 | jan 2 | jan 3 | pol 4 | jan 5 | pol 6 | anna -- select all oldest records that have duplicates (oldest = with lower id) SELECT id FROM people WHERE EXISTS( SELECT * FROM people AS tmp WHERE tmp.id > people.id AND tmp.name = people.name ); id ---- 1 2 3 -- delete duplicates DELETE FROM PEOPLE WHERE id IN ( SELECT id FROM people WHERE EXISTS( SELECT * FROM people AS tmp WHERE tmp.id > people.id AND tmp.name = people.name ) );