Description
Write a SQL query to find all duplicate emails in the users table. Return only the email column. **Output columns (in order):** email
Table:
users| Column | Type |
|---|---|
| id | INT |
| TEXT |
Examples
Input:
CREATE TABLE users (id INT, email TEXT); INSERT INTO users VALUES (1, 'john@test.com'), (2, 'jane@test.com'), (3, 'john@test.com');Output:
john@test.comExplanation:
john@test.com appears twice (ids 1 and 3), jane@test.com appears once. Only john@test.com is a duplicate.
Input:
CREATE TABLE users (id INT, email TEXT); INSERT INTO users VALUES (1, 'alice@company.com'), (2, 'bob@website.org'), (3, 'alice@company.com'), (4, 'charlie@domain.net'), (5, 'bob@website.org');Output:
alice@company.com
bob@website.orgExplanation:
alice@company.com appears twice (ids 1 and 3), and bob@website.org also appears twice (ids 2 and 5). charlie@domain.net appears only once, so it's not a duplicate. Both duplicate emails are returned.
Input:
CREATE TABLE users (id INT, email TEXT); INSERT INTO users VALUES (1, 'sarah@email.com'), (2, 'mike@test.org'), (3, 'lisa@sample.net'), (4, 'sarah@email.com'), (5, 'tom@domain.com'), (6, 'sarah@email.com');Output:
sarah@email.comExplanation:
sarah@email.com appears three times in the table (ids 1, 4, and 6), making it the only duplicate email.
Constraints
- •
Use GROUP BY and HAVING