Back to lessons

Hosting Operations

Find Duplicate Emails in SQLite

You need to find duplicate email values in a SQLite users table.

Command

sqlite3 app.db "SELECT email, count(*) FROM users GROUP BY email HAVING count(*) > 1;"

What changed

Nothing changes. The command groups users by email and prints repeated values.

Danger

safe

When to use it

Use after imports, failed uniqueness migrations, or account merge bugs.

When not to use it

Do not delete duplicates from this output alone; inspect IDs and references first.

Undo or recovery

No undo needed because this command is read-only.

Expected output

Email values with counts greater than one.

demo script

Disposable terminal steps

  1. sqlite3 app.db ".schema users"
  2. sqlite3 app.db "SELECT email, count(*) FROM users GROUP BY email HAVING count(*) > 1;"

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ sqlite3 app.db ".schema users"
CREATE TABLE users (
  id INTEGER PRIMARY KEY,
  email TEXT NOT NULL,
  created_at TEXT NOT NULL
);
CREATE UNIQUE INDEX idx_users_email ON users(email);
::exit-code::0
$ sqlite3 app.db "SELECT email, count(*) FROM users GROUP BY email HAVING count(*) > 1;"
alex@example.com|2
::exit-code::0

YouTube Short

Find duplicate emails.

Group by email and use HAVING to print only values that appear more than once.

LinkedIn hook

Duplicate account data is easier to spot with one grouped query.

Question: Do you check duplicates after CSV imports into SQLite?

experiments

A/B tests to run

Metric: comment_rate

A: Find duplicate accounts.

B: GROUP BY plus HAVING.