Duplicate Emails Problem
Description
LeetCode Problem 182.
Write a SQL query to find all duplicate emails in a table named Person.
1
2
3
4
5
6
7
+----+---------+
| Id | Email |
+----+---------+
| 1 | a@b.com |
| 2 | c@d.com |
| 3 | a@b.com |
+----+---------+
For example, your query should return the following for the above table:
1
2
3
4
5
+---------+
| Email |
+---------+
| a@b.com |
+---------+
MySQL Solution
1
2
3
4
5
select p.Email
from (select Email, count(Email) as count
from Person
group by Email) p
where p.count > 1
LeetCode Database - Easy
LeetCode 175
LeetCode 176
LeetCode 181
LeetCode 182
LeetCode 183
LeetCode 196
LeetCode 197
LeetCode 511
LeetCode 512
LeetCode 577
LeetCode 584
LeetCode 586
LeetCode 595
LeetCode 596
LeetCode 597
LeetCode 603
LeetCode 607
LeetCode 610
LeetCode 613
LeetCode 619
LeetCode 620
LeetCode 627
More LeetCode Database
MySQL Tutorials