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.

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

    Find all the cats. Show every column.

    From the lesson Filter with WHERE · Paws & Whiskers Shelter

    Write your query here…
    Show the answer

    Answer (PostgreSQL and SQLite)

    SELECT * FROM pets WHERE species = 'cat';

    Expected result (SQLite): 7 rows

    idnamespeciesbreedageweight_kgadoptedarrived_on
    2MochicatSiamese24.112025-11-02
    4LunacatNULL53.802026-02-03
    7PeppercatBengal13.212026-04-19
    11TofucatNULL114.602025-04-04
    13SockscatMaine Coon87.402025-08-17
    16OlivecatSiamese43.902026-03-22
    19PumpkincatNULL35.212025-10-31
  2. 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 answer

    Answer (PostgreSQL and SQLite)

    SELECT name, age FROM pets WHERE age > 6;

    Expected result (both engines): 5 rows

    nameage
    Pickles7
    Bruno9
    Tofu11
    Socks8
    Gizmo10
  3. 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 answer

    Answer (PostgreSQL and SQLite)

    SELECT name, species FROM pets WHERE species <> 'dog';

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

    namespecies
    Mochicat
    Lunacat
    Wafflesrabbit
    Peppercat
    Cloverrabbit
    Ziggybird
    Tofucat
    Sockscat
  4. 4

    Show the names of pets still waiting for a home (adopted is false).

    From the lesson Filter with WHERE · Paws & Whiskers Shelter

    Write your query here…
    Show 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. 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 answer

    Answer (PostgreSQL and SQLite)

    SELECT name, age FROM pets WHERE species = 'dog' AND age < 4;

    Expected result (both engines): 3 rows

    nameage
    Biscuit3
    Maple2
    Bean1
  6. 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 answer

    Answer (PostgreSQL and SQLite)

    SELECT name, age FROM pets WHERE age < 2 OR age > 9;

    Expected result (both engines): 5 rows

    nameage
    Waffles1
    Pepper1
    Tofu11
    Bean1
    Gizmo10
  7. 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 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

    namespeciesage
    Brunodog9
    Tofucat11
    Gizmodog10
  8. 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 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. 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 answer

    Answer (PostgreSQL and SQLite)

    SELECT name, weight_kg FROM pets WHERE weight_kg BETWEEN 3 AND 5;

    Expected result (both engines): 6 rows

    nameweight_kg
    Mochi4.1
    Luna3.8
    Pepper3.2
    Tofu4.6
    Olive3.9
    Juniper3.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.

More practice sets

Check your level

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