思路1
DELETE P1
FROM Person P1 JOIN Person P2
ON
P1.Email=P2.Email AND
P1.Id>P2.Id;MariaDB [test]> select * from Person p1 inner join Person p2 on p1.Email=p2.Email;
+----+------------------+----+------------------+
| Id | Email | Id | Email |
+----+------------------+----+------------------+
| 1 | john@example.com | 1 | john@example.com |
| 3 | john@example.com | 1 | john@example.com |
| 2 | bob@example.com | 2 | bob@example.com |
| 1 | john@example.com | 3 | john@example.com |
| 3 | john@example.com | 3 | john@example.com |
+----+------------------+----+------------------+MariaDB [test]> select * from Person p1 inner join Person p2 on p1.Email=p2.Email AND p1.Id>p2.Id;
+----+------------------+----+------------------+
| Id | Email | Id | Email |
+----+------------------+----+------------------+
| 3 | john@example.com | 1 | john@example.com |
+----+------------------+----+------------------+Last updated