Back to subject
MySQL/WHERE

Filter Down to What Matters

Practical lesson

Let's read a filtered query and see exactly which rows survive the condition and which don't.

SELECT * FROM students WHERE age > 16; checks every row in students and keeps only the ones where age is strictly greater than 16. Given the two rows from earlier (Ali, 16 and Sara, 17), only Sara's row satisfies the condition Ali's age of exactly 16 does not, since 16 is not greater than 16.

This is a subtle but important detail: > means strictly greater than. If you wanted to include exactly 16 as well, you'd use >= instead, which you'll formally cover in the next topic on comparison operators.

The result table has the same columns as students (id, name, age) because we used *, but now contains only 1 row instead of the original 2 WHERE narrowed the result set without touching the actual stored data at all.

This filter-then-read pattern deciding exactly which rows qualify is the single most-used skill in everyday SQL, and every topic from here builds more precise ways of writing that condition.

Try it yourself
Code

Starter example

Code
SELECT * FROM students WHERE age > 16;
Live preview
+----+------+-----+
| id  | name | age |
+----+------+-----+
| 2  | Sara | 17  |
+----+------+-----+
1 row in set