WHERE: only the rows you need

Filter rows with comparisons, and combine conditions with AND, OR and NOT.

Module 2: Filtering and sorting · Lesson 5 of 26 · 14 min read · Free

WHERE keeps only the rows that meet a condition. It comes after FROM:

Customers in Lagos
SELECT first_name, last_name, city
FROM customers
WHERE state = 'Lagos';

177 customers. Text in single quotes; numbers without.

Comparison operators

OperatorMeaningExample
=equalstatus = 'Delivered'
<> or !=not equalchannel <> 'Walk-in'
> <greater / less thanunit_price < 1000
>= <=at least / at mostquantity >= 6
SELECT name, unit_price
FROM products
WHERE unit_price < 1000;

returns six budget products, from Indomie at ₦250 to Close-Up at ₦950.

Dates compare as text in YYYY-MM-DD form, which works naturally: order_date >= '2026-01-01' means on or after 1 January 2026.

AND, OR, NOT

  • AND — both conditions must be true.
  • OR — at least one must be true.
  • NOT — reverses a condition.
SELECT order_id, order_date, channel
FROM orders
WHERE status = 'Delivered'
  AND order_date >= '2026-01-01';

Check yourself

Answer in your head first, then open each question to see the answer and why.

  1. Which WHERE clause returns customers in Lagos?

    • A WHERE state = Lagos
    • B WHERE state = 'Lagos'
    • C WHERE 'state' = Lagos
    • D WHERE state == "Lagos"
    Show the answer

    B) WHERE state = 'Lagos' — Compare the column to a text value in single quotes.

  2. What does <> mean?

    • A Less or greater, i.e. not equal
    • B Between
    • C Join
    • D Approximately
    Show the answer

    A) Less or greater, i.e. not equal — <> means not equal (as does != in SQLite).

  3. WHERE a OR b AND c is evaluated as…

    • A (a OR b) AND c
    • B a OR (b AND c)
    • C An error
    • D a AND b AND c
    Show the answer

    B) a OR (b AND c) — AND is evaluated before OR — use brackets to be clear.

More free lessons: What SQL is, and why employers want it · Install DB Browser and open the practice database · COUNT, SUM, AVG, MIN and MAX · INNER JOIN: combine two tables · CASE: if-then logic inside a query · INSERT, UPDATE and DELETE — safely · From a business question to an answer