SQL WHERE practice: 9 exercises with answers
Updated · Tested on PostgreSQL 18.6 and SQLite 3.54.1 (results generated , re-checked on every release)
Nine exercises on filtering rows: comparisons, true/false columns, combining conditions with AND and OR, and the IN and BETWEEN shortcuts. All on the shelter's pets table.
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 SQL WHERE clause: filtering rows 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
Find all the cats. Show every column.
From the lesson Filter with WHERE · Paws & Whiskers Shelter
Write your query here…Show the answerHide the answer
Answer (PostgreSQL and SQLite)
SELECT * FROM pets WHERE species = 'cat';Expected result (SQLite): 7 rows
id name species breed age weight_kg adopted arrived_on 2 Mochi cat Siamese 2 4.1 1 2025-11-02 4 Luna cat NULL 5 3.8 0 2026-02-03 7 Pepper cat Bengal 1 3.2 1 2026-04-19 11 Tofu cat NULL 11 4.6 0 2025-04-04 13 Socks cat Maine Coon 8 7.4 0 2025-08-17 16 Olive cat Siamese 4 3.9 0 2026-03-22 19 Pumpkin cat NULL 3 5.2 1 2025-10-31 - 2
Which pets are older than 6? Show their name and age.
From the lesson Filter with WHERE · Paws & Whiskers Shelter
Write your query here…Show the answerHide the answer
Answer (PostgreSQL and SQLite)
SELECT name, age FROM pets WHERE age > 6;Expected result (both engines): 5 rows
name age Pickles 7 Bruno 9 Tofu 11 Socks 8 Gizmo 10 - 3
Show the name and species of every pet that isn't a dog.
From the lesson Filter with WHERE · Paws & Whiskers Shelter
Write your query here…Show the answerHide the answer
Answer (PostgreSQL and SQLite)
SELECT name, species FROM pets WHERE species <> 'dog';Expected result (both engines): first 8 of 12 rows
name species Mochi cat Luna cat Waffles rabbit Pepper cat Clover rabbit Ziggy bird Tofu cat Socks cat - 4
Show the names of pets still waiting for a home (
adoptedis false).From the lesson Filter with WHERE · Paws & Whiskers Shelter
Write your query here…Show the answerHide the answer
Answer (PostgreSQL and SQLite)
SELECT name FROM pets WHERE adopted = false;Expected result (both engines): first 8 of 12 rows
name Biscuit Pickles Luna Bruno Clover Ziggy Tofu Socks - 5
Find dogs younger than 4. Show name and age.
From the lesson AND, OR and IN · Paws & Whiskers Shelter
Write your query here…Show the answerHide the answer
Answer (PostgreSQL and SQLite)
SELECT name, age FROM pets WHERE species = 'dog' AND age < 4;Expected result (both engines): 3 rows
name age Biscuit 3 Maple 2 Bean 1 - 6
Find pets younger than 2 or older than 9. Show name and age.
From the lesson AND, OR and IN · Paws & Whiskers Shelter
Write your query here…Show the answerHide the answer
Answer (PostgreSQL and SQLite)
SELECT name, age FROM pets WHERE age < 2 OR age > 9;Expected result (both engines): 5 rows
name age Waffles 1 Pepper 1 Tofu 11 Bean 1 Gizmo 10 - 7
Find cats or dogs older than 8. Show name, species and age.
From the lesson AND, OR and IN · Paws & Whiskers Shelter
Write your query here…Show the answerHide the answer
Answer (PostgreSQL and SQLite)
SELECT name, species, age FROM pets WHERE (species = 'cat' OR species = 'dog') AND age > 8;Expected result (both engines): 3 rows
name species age Bruno dog 9 Tofu cat 11 Gizmo dog 10 - 8
Show the names of all rabbits and birds, using
IN.From the lesson AND, OR and IN · Paws & Whiskers Shelter
Write your query here…Show the answerHide the answer
Answer (PostgreSQL and SQLite)
SELECT name FROM pets WHERE species IN ('rabbit', 'bird');Expected result (both engines): 5 rows
name Waffles Clover Ziggy Kiwi Juniper - 9
Which pets weigh between 3 and 5 kg (inclusive)? Show name and weight_kg.
From the lesson AND, OR and IN · Paws & Whiskers Shelter
Write your query here…Show the answerHide the answer
Answer (PostgreSQL and SQLite)
SELECT name, weight_kg FROM pets WHERE weight_kg BETWEEN 3 AND 5;Expected result (both engines): 6 rows
name weight_kg Mochi 4.1 Luna 3.8 Pepper 3.2 Tofu 4.6 Olive 3.9 Juniper 3.4
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.
- Filter with WHERE2 more exercises · free, no account needed
- AND, OR and IN1 more exercise · free, no account needed
More practice sets
Check your level
The free SQL test takes about 10 minutes and tells you which lesson to start with.