Duplicate Emails - Problem
You have a table Person with the following structure:
id(int): Primary key, unique identifier for each personemail(varchar): Email address (guaranteed not NULL, no uppercase letters)
Write a SQL query to find all duplicate emails in the table.
Return the result in any order.
Table Schema
Person
| Column Name | Type | Description |
|---|---|---|
id
PK
|
int | Primary key, unique identifier |
email
|
varchar | Email address (no NULL values) |
Primary Key: id
Note: Each row represents a person with their email. Multiple people can have the same email.
Input & Output
Example 1 — Basic Duplicate Detection
Input Table:
| id | |
|---|---|
| 1 | a@b.com |
| 2 | c@d.com |
| 3 | a@b.com |
Output:
| a@b.com |
💡 Note:
The email a@b.com appears twice (id 1 and id 3), so it's returned as a duplicate. The email c@d.com appears only once, so it's not included in the result.
Example 2 — Multiple Duplicates
Input Table:
| id | |
|---|---|
| 1 | john@gmail.com |
| 2 | bob@gmail.com |
| 3 | john@gmail.com |
| 4 | alice@yahoo.com |
| 5 | bob@gmail.com |
Output:
| bob@gmail.com |
| john@gmail.com |
💡 Note:
Both john@gmail.com and bob@gmail.com appear twice, so both are returned as duplicates. alice@yahoo.com appears only once and is not included.
Example 3 — No Duplicates
Input Table:
| id | |
|---|---|
| 1 | unique1@test.com |
| 2 | unique2@test.com |
| 3 | unique3@test.com |
Output:
💡 Note:
All emails are unique, so no duplicates are found. The result is an empty table.
Constraints
-
1 ≤ Person.id ≤ 1000 -
emailis guaranteed to be not NULL -
emailcontains no uppercase letters
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code