WHERE

Basic SQL
≈ 1 min read

WHERE filters rows

WHERE defines a condition that a row must satisfy to appear in the query result. Without it, a normal SELECT considers every row in the table.

SELECT id, name, price
FROM products
WHERE price > 1000;

For each row, the database checks the condition price > 1000. Only rows for which the condition is satisfied appear in the result.

WHERE does not change data

Filtering affects only the set of rows returned by the query. The records stored in the table remain unchanged.

SELECT name
FROM users
WHERE active = TRUE;

This query returns the names of active users, but it does not change the active value in any row.

A WHERE condition should describe the rows you want to keep. It helps to read the query literally: “take data from the table and keep the rows where the condition is true.” This approach remains useful when conditions become more complex.