LeetCode Delete Duplicate Emails
Problem Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smalle...
Problem
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 | [email protected] |
| 2 | [email protected] |
| 3 | [email protected] |
+----+------------------+
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 | [email protected] |
| 2 | [email protected] |
+----+------------------+删除邮件重复的记录,保留Id最小的
MySQL
DELETE p1 FROM Person p1, Person p2 WHERE p1.Email = p2.Email AND p1.Id > p2.Id;
分析
无
看完题解,马上用 240 关实战检验掌握度
覆盖 GESP 1~8 级考纲心法、CSP-J 双栏阅读程序、错题动态变式推演与 90/120 分钟全真模考。
配套题解代码归档于 yummy-code 仓库,完整知识点索引见 GESP Wiki。
同专栏相关推荐
LeetCode Combine Two Tables
Problem Table: Person Table: Address Write a SQL query for a report that provides the following information for each person in the Pers...
LeetCode Second Highest Salary
Problem Write a SQL query to get the second highest salary from the Employee table. For example, given the above Employee table, the qu...
LeetCode Customers Who Never Order
Problem Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers w...
OneCoder
始于 2012持续记录 C++ GESP/CSP 信奥算法、Java 服务端架构与 Python 工程实战。官方唯一域名:coderli.com