SQL guide · Filtering
SQL AND: Require Every Condition to Be True
The AND operator joins two or more conditions so that a row is returned only when all of them are true. It is the tool for narrowing a result: each extra AND can only keep the same rows or remove some, never add any.
You can use AND anywhere a condition is accepted, most often in WHERE, but also in HAVING, in JOIN ... ON clauses and inside CASE expressions. Chains of several AND conditions are common in reporting queries, for example filtering by date range, status and region at once.
Because conditions can evaluate to unknown when NULL is involved, AND follows three-valued logic. True AND unknown is unknown, and a row is only returned when the whole expression is true, so a NULL in any tested column quietly drops the row.
Basic syntax
SELECT column1, column2
FROM table_name
WHERE condition1
AND condition2
AND condition3;Each condition is a complete boolean expression. Evaluation order is not guaranteed to be left to right, so do not rely on one condition protecting another from an error. When AND and OR appear together, AND is applied first unless parentheses say otherwise. It also helps to put each condition on its own line, so that a reviewer can see at a glance which filters apply to the query.
SQL AND examples
Two conditions on different columns
Both tests must pass. This returns customers who live in Canada and have an active account, so a Canadian customer with a closed account is excluded.
SELECT customer_id, name
FROM customers
WHERE country = 'Canada'
AND status = 'active';A range built from AND
Two comparisons on the same column create a range. This is equivalent to BETWEEN for inclusive bounds, but it also lets you make one end exclusive, which is useful for date ranges.
SELECT order_id, order_date, total
FROM orders
WHERE order_date >= '2026-01-01'
AND order_date < '2026-02-01';AND together with OR
Parentheses control precedence. Without them, the AND would bind to only the second OR branch. Here the stock condition applies to both categories.
SELECT product_id, name, category, stock
FROM products
WHERE (category = 'Books' OR category = 'Games')
AND stock > 0;AND with NOT
You can mix AND with negated conditions to exclude cases. This lists employees in sales who are not managers and who joined before 2024.
SELECT employee_id, name
FROM employees
WHERE department = 'Sales'
AND NOT title = 'Manager'
AND hire_date < '2024-01-01';Where SQL dialects differ
PostgreSQL: Supports boolean columns directly, so WHERE is_active AND is_verified is valid. The planner may reorder conditions freely.
MySQL: Also accepts the non-standard && as a synonym for AND, though it is deprecated in some contexts, so prefer the keyword. Comparison results are 1, 0 or NULL.
SQL Server: Has no boolean type, so each side of AND must be a comparison or predicate. Short-circuit evaluation is not guaranteed.
SQLite: Treats any non-zero numeric value as true, so WHERE flag1 AND flag2 works on integer columns.
Common mistakes
- Assuming
ANDis evaluated before a safe-guard condition. For example,WHERE x <> 0 AND 10 / x > 1can still raise a divide-by-zero error because order is not guaranteed. - Mixing
ANDandORwithout parentheses and getting rows that violate the intended rule. Always bracket mixed logic. - Writing
WHERE country = 'US' AND 'CA'. Each side ofANDmust be a full condition, so repeat the column name. - Expecting rows with NULL values to survive. If any condition is unknown because of NULL, the row is excluded.
Related SQL guides
Need help writing the SQL?
Describe your tables and the result you want, then review the generated query against your database before running it.
Try the AI SQL generator