SQL Practice Problem #023

Find duplicate customer emails

Return email values that appear more than once in the customers table.

Problem

Task

Return email values that appear more than once in the customers table.

Schema

Table Schema

customers(id, name, email)

Input

Sample Data

idnameemail
1Aliceshared@example.com
2Bobbob@example.com
3Chloeshared@example.com

Output

Expected Output

emailduplicate_count
shared@example.com2

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

Related Problems