Skip to content

Stockertim Dictionary · Technology

WHERE clause

Also called SQL WHERE, WHERE condition, row filter in SQL

In short

The part of an SQL query that keeps only the rows meeting a stated condition, applied to individual rows before any grouping or summarising takes place.

  • Beginner
  • Concept
  • Checked

In detail

WHERE is the row filter of SQL. It follows FROM and holds a condition that is tested against each row in turn; rows for which the condition is true pass through and the rest are discarded. A condition can compare a column with a value, such as WHERE country = 'Ghana', or with another column, such as WHERE paid_on > due_on.

Conditions are built from comparison operators (=, <>, <, >, <= and >=), from AND, OR and NOT, and from helpers such as IN for a list of values, BETWEEN for an inclusive range and LIKE for text patterns. AND is evaluated before OR, so a condition mixing them needs brackets to say what is meant: WHERE (city = 'Lagos' OR city = 'Abuja') AND status = 'active'.

Missing values need special handling. A blank in a database is NULL, meaning unknown, and any ordinary comparison with NULL is neither true nor false, so the row is dropped. To find or exclude blanks the query must say IS NULL or IS NOT NULL; writing = NULL never matches anything.

Because WHERE runs before GROUP BY, it filters raw rows and cannot refer to a total; that is the job of HAVING. Filtering early also matters for speed. A condition on an indexed column lets the database jump straight to the relevant rows instead of reading the whole table, which on a large table can be the difference between milliseconds and minutes.

Worked example

An events company in Kigali has 5,000 ticket rows and wants paid tickets for one venue.

  1. Write: SELECT ticket_id, price FROM tickets WHERE venue = 'Convention Hall' AND status = 'paid';
  2. 1,200 rows are for Convention Hall, and 900 of those are paid.
  3. Share of the venue's tickets that are paid: 900 / 1,200 = 75%

The query returns 900 rows; unpaid and other-venue tickets never reach the result.

In practice

Almost every working query has a WHERE clause: one date range, one region, one product line, or only active records. Analysts often check a filter by running a COUNT with and without it, so they know how many rows it removed.

Watch out

  • A condition such as status <> 'closed' silently leaves out rows where status is NULL; add OR status IS NULL if those rows belong in the answer.
  • Mixing AND with OR without brackets is a common source of quietly wrong results.

Learn it properly

Official sources

Facts last checked on 9 November 2026.

Education, not advice: the Stockertim Dictionary explains what terms mean. It never recommends buying or selling anything.

English