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.
The tables
- pets (id, name, species, breed, age, weight_kg, adopted, arrived_on)
- adoption_requests (id, pet_name, email, phone, requested_on, budget)
- 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 answerHide 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
id pet_key 1 biscuit 2 mochi 3 biscuit 4 luna 5 pickles 6 luna 7 tofu 8 pepper - 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 answerHide 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
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 answerHide 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
id budget_usd 1 120 2 80 3 150 4 NULL 5 60 6 95 7 200 8 75 - 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 answerHide 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
email requests ana@mail.com 2 ben@mail.com 2 cara@mail.com 2 gus@mail.com 2 - 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 answerHide 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
email requested_on ana@mail.com 2026-10-05 ben@mail.com 2026-10-16 cara@mail.com 2026-10-09 dev@mail.com 2026-10-07 eli@mail.com 2026-10-10 fay@mail.com 2026-10-12 gus@mail.com 2026-10-20 hana@mail.com 2026-10-18 - 6
Match every request to its pet in
petsdespite 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 answerHide 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
id name species 1 Biscuit dog 2 Mochi cat 3 Biscuit dog 4 Luna cat 5 Pickles dog 6 Luna cat 7 Tofu cat 8 Pepper cat
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.
- Tidy text and numbers4 more exercises · sqlstreak Pro
- Finding duplicates1 more exercise · sqlstreak Pro
More practice sets
Check your level
The free SQL test takes about 10 minutes and tells you which lesson to start with.