Problem
Write a SQL query to find all duplicate emails in a table named Person.
1 | |
For example, your query should return the following for the above table:
1 | |
Note: All emails are in lowercase.
Explanation 1
-
To return duplicated emails, it means we compare emails that are the same. When comparing and returning the common attributes, we can use
INNER JOINtwo tables. -
The join condition is first table’s email equal to second table’s email, where first table’s id not equal to second table’s id.
Solution 1
1 | |
Explanation 2
- We can also use
GROUP BYthe emails andHAVINGthe count of email greater than 1.
Solution 2
1 | |