Skip to main content

Chapter 2 · Filtering

SQL WHERE Clause Practice

WHERE keeps only the rows that match a condition. Almost every real question has one: orders over $500, customers in one state, products whose name contains a word, payments that failed.

The tricky parts are combining conditions correctly with AND and OR, matching text patterns, and handling missing values: NULL is never equal to anything, not even another NULL.

Start practising16 exercises · 15 easy, 1 medium, 0 hard

Key ideas

Comparison
=, <>, <, >, <=, >= on numbers, text and dates (dates stored as YYYY-MM-DD compare correctly as text).
AND / OR
Combine conditions. Use parentheses whenever you mix them, so the logic is explicit.
IN, BETWEEN, LIKE
Match a list of values, an inclusive range, or a text pattern with % and _.
IS NULL
The only way to find missing values. column = NULL never matches.

Example: Large shipped or delivered orders from 2025

SELECT id, order_date, total_amount
FROM orders
WHERE status IN ('shipped', 'delivered')
  AND total_amount > 500
  AND order_date >= '2025-01-01';

IN replaces two OR conditions, and every condition must be true for a row to be kept.

In interviews

Say your assumptions out loud: does "orders over $500" include exactly $500? Do cancelled orders count? Interviewers reward clarifying the filter before writing it.

All 16 Filtering exercises

Ordered from easiest to hardest. Each one runs on a real database with instant feedback.