WHERE Clause

The WHERE clause filters rows so a query returns only those that meet a condition. Without it, a query acts on every row in the table.

SQL

You can combine conditions with AND, OR, and NOT, and use comparison operators like =, <, >, and <>. Other useful keywords include BETWEEN, IN, LIKE (for pattern matching), and IS NULL.

WHERE works not just with SELECT, but also with UPDATE and DELETE — and there it is critical, because forgetting it changes or removes every row.

Syntax

SELECT columns FROM table_name WHERE condition;

Examples

SQL

SELECT name, age
FROM users
WHERE age >= 18 AND name LIKE 'A%';

Output:

name   age
-----  ---
Alice  30

Learn it in a lesson

See also

Back to the Dictionary