- Delete Duplicate Emails My Submissions QuestionEditorial Solution
Total Accepted: 14121 Total Submissions: 73321 Difficulty: Easy
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.
+—-+——————+
| Id | Email |
+—-+——————+
| 1 | john@example.com |
| 2 | bob@example.com |
| 3 | john@example.com |
+—-+——————+
Id is the primary key column for this table.
For example, after running your query, the above Person table should have the following rows:
+—-+——————+
| Id | Email |
+—-+——————+
| 1 | john@example.com |
| 2 | bob@example.com |
+—-+——————+
刚开始看数据库,借鉴了别人一下
delete from Person where Id not in
(select A.Id from (select min(Id) as Id from Person group by Email) A);
本文介绍了一个SQL查询案例,用于从Person表中删除所有重复的电子邮件条目,仅保留基于最小ID的唯一电子邮件。通过一个具体例子展示了如何实现这一目标。
437

被折叠的 条评论
为什么被折叠?



