I would do:
delete from t where ID not in (select min(ID) from table t group by refID having count(*) > 1) and refID in (select refID from table t group by refID having count(*) > 1)
refId criteria are duplicates, and the identifier is different from the minimum (id) of the duplicates. This will work better if refId is indexed.
otherwise, and provided that you can issue the next request several times until it removes anything
delete from t where ID in (select max(ID) from table t group by refID having count(*) > 1)
source share