Problem
Task
Return email values that appear more than once in the customers table.
Schema
Table Schema
customers(id, name, email)
Input
Sample Data
| id | name | |
|---|---|---|
| 1 | Alice | [email protected] |
| 2 | Bob | [email protected] |
| 3 | Chloe | [email protected] |
Output
Expected Output
| duplicate_count | |
|---|---|
| [email protected] | 2 |
Answer
Check Your Solution
Show Answer and Explanation
Correct Answer
SELECT email, COUNT(*) AS duplicate_count
FROM customers
GROUP BY email
HAVING COUNT(*) > 1;
Explanation
GROUP BY email creates one group per email value. HAVING COUNT(*) > 1 keeps only groups with duplicates.
Common Mistakes
- Using WHERE COUNT(*) > 1.
- Grouping by id, which makes every row its own group.
- Selecting name when the output is one row per email value.
Concepts
Related Concepts
GROUP BY
HAVING
Data Quality
COUNT
Next practice