Skip to content
>_sqlbuddy
easyGROUP BYHAVING

Duplicate Emails

List the email addresses that appear more than once in the person table.

Start practice

Prompt

Duplicate Emails

Prompt

Given the person table below, write a query that returns the email address of every person whose email appears more than once.

  • Each duplicate email should be returned once, regardless of how many times it appears.
  • Only the email column should be in the result.
  • person.email may be NULL; a NULL value is not an email and must not be treated as a duplicate.

Example

idemail
1a@example.com
2b@example.com
3a@example.com
4c@example.com

Expected result:

email
a@example.com

Constraints

  • person.id is the primary key.
  • person.email is nullable.

Tips

  • GROUP BY email then filter the groups with HAVING COUNT(*) > 1.
  • Remember that HAVING filters groups _after_ aggregation, while WHERE filters rows _before_.

Expected concepts

  • GROUP BY
  • HAVING
  • COUNT
  • NULL handling

Schema

CREATE TABLE person (
    id    INTEGER PRIMARY KEY,
    email TEXT  -- NULL allowed
);

Sample data

INSERT INTO person (id, email) VALUES
  (1, 'a@example.com'),
  (2, 'b@example.com'),
  (3, 'a@example.com'),
  (4, 'c@example.com');

Additional hidden fixtures are applied during validation to test edge cases.