MySQL AND Operator
MySQL AND Operator: Combining Multiple Conditions
The MySQL AND operator combines two or more boolean conditions in a WHERE, ON, or HAVING clause. A row appears in the output only when every condition joined by AND evaluates to true.
Basic Syntax
Chain multiple filters using AND to narrow down large result sets accurately:
SELECT columns
FROM table_name
WHERE condition1 AND condition2 AND condition3;
Practical SQL Example
The query below finds active electronics in demo_products that are in stock and cost less than 100 dollars.
SELECT id, product_name, price, stock_qty
FROM demo_products
WHERE category = 'electronics'
AND is_active = 1
AND stock_qty > 0
AND price < 100.00
ORDER BY price ASC;
| id | product_name | price | stock_qty |
|---|---|---|---|
| 33 | USB-C Fast Charger | 24.99 | 48 |
| 41 | Bluetooth Tracker | 39.00 | 19 |
Common Mistakes and Best Practices
- Mind Operator Precedence (
ANDBeforeOR): MySQL evaluatesANDbeforeOR. Always wrapORbranches in parentheses:WHERE is_active = 1 AND (role = 'admin' OR role = 'editor'). Without parentheses, inactive editors slip through. - Order Composite Index Columns Smartly: When filtering with
WHERE tenant_id = 5 AND status = 'open' AND created_at >= '2026-08-01', list equality columns (tenant_id,status) before range columns (created_at) in your index definition. - Remember Three-Valued Logic: If one side of
ANDisFALSE, the result isFALSE; if one side isTRUEand the other isNULL, the result isUNKNOWNand the row is excluded.
Frequently Asked Questions
Is there a limit to how many AND conditions I can chain?
There is no practical limit in everyday queries, though keeping conditions readable and index-backed helps performance.
Does AND short-circuit in MySQL?
MySQL optimizes evaluation order dynamically using indexes and column statistics rather than strictly left-to-right.
What happens if WHERE a = 1 AND b = NULL is executed?
b = NULL evaluates to UNKNOWN, so TRUE AND UNKNOWN produces UNKNOWN and returns zero rows; use b IS NULL instead.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.