Skip to content
C

Duplicate Emails

Easysql

The email column in employees should be unique, but isn't currently enforced. Write a query returning every email that appears more than once, along with a cnt column showing how many times it appears, ordered by email.

sql
CREATE TABLE departments ( id INTEGER PRIMARY KEY, name TEXT NOT NULL ); CREATE TABLE employees ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, email TEXT NOT NULL, department_id INTEGER );

Sample data (this is what your query runs against when you press Run):

sql
INSERT INTO departments (id, name) VALUES (1, 'Engineering'), (2, 'Sales'), (3, 'Marketing'); INSERT INTO employees (id, name, email, department_id) VALUES (1, 'Asha', 'asha@co.com', 1), (2, 'Rohan', 'rohan@co.com', 1), (3, 'Neha', 'neha@co.com', 2), (4, 'Vikram', 'asha@co.com', 2), (5, 'Priya', 'priya@co.com', 99), (6, 'Karan', 'karan@co.com', 3), (7, 'Divya', 'karan@co.com', 3), (8, 'Aman', 'aman@co.com', 88);

Input (stdin)

Output

Run your code to see output here...