LeetCode - Delete Duplicate Emails

时间:2022-05-17 04:37:55

Discription:Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.

删除重复的Email地址,保留Id最小的那个。

使用自身连接循环即可。

# Write your MySQL query statement below
delete p1 from Person p1, Person p2
where p1.Email=p2.Email and p1.Id>p2.Id;