2020-04-13

删除重复保留最大或最小

Screen Shot 2020-04-13 at 2.51.56 PM.png

Solution 1

DELETE P1
FROM Person AS P1, Person AS P2
WHERE P1.Email=P2.Email AND P1.Id>P2.Id

自连接,删除Email相同,但是ID大的记录

Solution 2

DELECT FROM PERSON
WHERE id not in (SELECT P1.id not in
       ((SELECT min(Id) as id 
       From Person
      Group by Email) as P1)

你可能感兴趣的:(2020-04-13)