delete from A where UserName in (select UserName from A group by UserName having count(UserName)>1) and UserID not in (select min(UserID) from A group by UserName having count(UserName)>1)