196. 删除重复的电子邮箱
难度系数: 简单
Write an SQL query to delete all the duplicate emails, keeping only one unique email with the smallest id. Note that you are supposed to write a DELETE statement and not a SELECT one.
After running your script, the answer shown is the Person table. The driver will first compile and run your piece of code and then show the Person table. The final order of the Person table does not matter.
编写一个SQL删除语句来删除所有重复的电子邮件,只保留一个id最小的唯一电子邮件。
以 任意顺序 返回结果表。 (注意: 仅需要写删除语句,将自动对剩余结果进行查询)
SQL结构
1 | Create table If Not Exists Person (Id int, Email varchar(255)) |
示例 1:
1 | 输入: |
解法:
1 | DELETE p1 FROM person p1, person p2 |