Skip to content

Commit b73597f

Browse files
Delete Duplicate Emails
1 parent ee4fbb0 commit b73597f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Delete Duplicate Emails
3+
https://leetcode.com/problems/delete-duplicate-emails/
4+
5+
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.
6+
7+
+----+------------------+
8+
| Id | Email |
9+
+----+------------------+
10+
11+
12+
13+
+----+------------------+
14+
Id is the primary key column for this table.
15+
For example, after running your query, the above Person table should have the following rows:
16+
17+
+----+------------------+
18+
| Id | Email |
19+
+----+------------------+
20+
21+
22+
+----+------------------+
23+
Note:
24+
25+
Your output is the whole Person table after executing your sql. Use delete statement.
26+
*/
27+
28+
DELETE person FROM Person person, Person person2
29+
WHERE person.email = person2.email AND person.id > person2.id;

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ To run a specific problem in your console, go to the file test, add the call to
9090
| [Customers Who Never Order](/LeetcodeProblems/Databases/Customers_Who_Never_Order.sql)| Easy | https://leetcode.com/problems/customers-who-never-order |
9191
| [Reformat Department Table](/LeetcodeProblems/Databases/Reformat_Department_Table.sql) | Easy | https://leetcode.com/problems/reformat-department-table |
9292
| [Employees Earning More Than Their Managers](/LeetcodeProblems/Databases/Employees_Earning_More_Than_Their_Managers.sql) | Easy | https://leetcode.com/problems/employees-earning-more-than-their-managers/ |
93+
| [Delete Duplicate Emails](LeetcodeProblems/Databases/Delete_Duplicate_Emails.sql) | Easy | https://leetcode.com/problems/delete-duplicate-emails |
9394

9495
### UtilsClasses
9596

0 commit comments

Comments
 (0)