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




Related Posts

Department Top Three Salaries Problem

LeetCode 185. Write a SQL query to find employees who...

Department Highest Salary Problem

LeetCode 184. Write a SQL query to find employees who...

Rising Temperature Problem

LeetCode 197. Write an SQL query to find all dates’...

Delete Duplicate Emails Problem

LeetCode 196. Write a SQL query to delete all duplicate...

Duplicate Emails Problem

LeetCode 182. Write a SQL query to find all duplicate...

Customers Who Never Order Problem

LeetCode 183. Write a SQL query to find all customers...