delete from TableName where id in(
select id from(
select id from TableName where name in (select name from TableName group by name having count(name) > 1)
and id not in(select id from TableName group by name having count(name )>1))t
)