SQL data cleaning practice: 6 exercises with answers

Updated · Tested on PostgreSQL 18.6 and SQLite 3.54.1 (results generated , re-checked on every release)

Six exercises on a messy web-form import: trimming and lowercasing names and emails, turning $25 style budgets into numbers, finding people who signed up twice, and matching dirty names to clean ones.

Write each query, press Check answer and get told right away whether your result matches. Stuck? Take a hint, or open the answer. New to the topic? Read the Data cleaning in SQL guide first.

Answers are checked on the engine you pick.
The tables

Paws & Whiskers Shelter

  • pets (id, name, species, breed, age, weight_kg, adopted, arrived_on)
  • adoption_requests (id, pet_name, email, phone, requested_on, budget)
  1. 1

    Show each request's id and its pet_name trimmed and in small letters, as pet_key.

    From the lesson Tidy text and numbers · Paws & Whiskers Shelter

    Write your query here…
    Show the answer

    Answer (PostgreSQL and SQLite)

    SELECT id, LOWER(TRIM(pet_name)) AS pet_key FROM adoption_requests;

    Expected result (both engines): first 8 of 12 rows

    idpet_key
    1biscuit
    2mochi
    3biscuit
    4luna
    5pickles
    6luna
    7tofu
    8pepper
  2. 2

    How many different people sent requests? Count the distinct emails after trimming and lowercasing them.

    From the lesson Tidy text and numbers · Paws & Whiskers Shelter

    Write your query here…
    Show the answer

    Answer (PostgreSQL and SQLite)

    SELECT COUNT(DISTINCT LOWER(TRIM(email))) FROM adoption_requests;

    Expected result (SQLite): 1 row

    COUNT(DISTINCT LOWER(TRIM(email)))
    8
  3. 3

    Turn every budget into a number called budget_usd: trim it, strip the $, make empty or missing budgets NULL, then cast. Show id and budget_usd.

    From the lesson Tidy text and numbers · Paws & Whiskers Shelter

    Write your query here…
    Show the answer

    Answer (PostgreSQL and SQLite)

    SELECT id, CAST(NULLIF(REPLACE(TRIM(budget), '$', ''), '') AS INTEGER) AS budget_usd FROM adoption_requests;

    Expected result (both engines): first 8 of 12 rows

    idbudget_usd
    1120
    280
    3150
    4NULL
    560
    695
    7200
    875
  4. 4

    Which people (by cleaned email) sent more than one request? Show email and requests.

    From the lesson Finding duplicates · Paws & Whiskers Shelter

    Write your query here…
    Show the answer

    Answer (PostgreSQL and SQLite)

    SELECT LOWER(TRIM(email)) AS email, COUNT(*) AS requests FROM adoption_requests GROUP BY LOWER(TRIM(email)) HAVING COUNT(*) > 1;

    Expected result (SQLite): 4 rows

    emailrequests
    ana@mail.com2
    ben@mail.com2
    cara@mail.com2
    gus@mail.com2
  5. 5

    Keep only each person's latest request date. Show the cleaned email and requested_on (the latest date).

    From the lesson Finding duplicates · Paws & Whiskers Shelter

    Write your query here…
    Show the answer

    Answer (PostgreSQL and SQLite)

    SELECT LOWER(TRIM(email)) AS email, MAX(requested_on) AS requested_on FROM adoption_requests GROUP BY LOWER(TRIM(email));

    Expected result (SQLite): 8 rows

    emailrequested_on
    ana@mail.com2026-10-05
    ben@mail.com2026-10-16
    cara@mail.com2026-10-09
    dev@mail.com2026-10-07
    eli@mail.com2026-10-10
    fay@mail.com2026-10-12
    gus@mail.com2026-10-20
    hana@mail.com2026-10-18
  6. 6

    Match every request to its pet in pets despite the messy names. Show request id, the pet's name and species.

    From the lesson Finding duplicates · Paws & Whiskers Shelter

    Write your query here…
    Show the answer

    Answer (PostgreSQL and SQLite)

    SELECT r.id, p.name, p.species FROM adoption_requests r JOIN pets p ON LOWER(p.name) = LOWER(TRIM(r.pet_name));

    Expected result (SQLite): first 8 of 12 rows

    idnamespecies
    1Biscuitdog
    2Mochicat
    3Biscuitdog
    4Lunacat
    5Picklesdog
    6Lunacat
    7Tofucat
    8Peppercat

The lessons have more like these

Each lesson teaches the idea step by step first, then gives you exercises with instant feedback and a daily streak.

More practice sets

Check your level

The free SQL test takes about 10 minutes and tells you which lesson to start with.