sql notes: leetcode#182 duplicate emails

Problem


Write a SQL query to find all duplicate emails in a table named Person.

1
2
3
4
5
6
7
+----+---------+
| Id | Email |
+----+---------+
+----+---------+

For example, your query should return the following for the above table:

1
2
3
4
5
+---------+
| Email |
+---------+
+---------+

Analysis


Group by Email and output groups that appear more than once.

Solution


1
SELECT Email FROM Person GROUP BY Email HAVING COUNT(*) > 1;

182. Duplicate Emails
(中文版) SQL 笔记: Leetcode#182 Duplicate Emails