WHERE
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.
Check yourself
Exercise review
The mentor knows the solution and will help you reach it independently
Sign in to use the Mentor
The Mentor uses the current exercise and your conversation history.
Sign in
Review the key nuances and the answer after making your own attempt.
Sign in to view the solution
The solution and explanation are available after signing in.
Sign in