The MySQL OR operator combines two or more conditions in a WHERE or HAVING clause and returns a row if at least one condition is true. You use it whenever a query must match several alternative categories, statuses, or regions.
Place OR between alternative conditions inside WHERE:
SELECT columns
FROM table_name
WHERE condition1 OR condition2;
This query fetches orders in demo_orders that are either still pending review or flagged for manual check.
SELECT id, customer_id, status, total_amount
FROM demo_orders
WHERE status = 'pending'
OR status = 'on_hold'
ORDER BY id DESC;
| id | customer_id | status | total_amount |
|---|---|---|---|
| 108 | 12 | on_hold | 149.00 |
| 104 | 7 | pending | 54.50 |
AND/OR Logic: Because AND has higher precedence than OR, WHERE a = 1 AND b = 2 OR c = 3 means (a = 1 AND b = 2) OR c = 3. Add parentheses explicitly so your intent is unmistakable.OR Chains with IN: Instead of writing status = 'paid' OR status = 'shipped' OR status = 'delivered', write status IN ('paid', 'shipped', 'delivered') for cleaner SQL and faster range optimization.OR Index Scans: Filtering WHERE customer_id = 10 OR email = '[email protected]' can force a full table scan unless both columns are indexed individually or rewritten with UNION.IN instead of OR in MySQL?Use IN (...) whenever every condition tests the exact same column against multiple constant values.
OR across two unindexed columns slow down large tables?MySQL cannot use a single B-tree index scan across two unrelated columns unless it merges separate index scans or falls back to a full table scan.
OR behave with NULL values?TRUE OR UNKNOWN evaluates to TRUE, whereas FALSE OR UNKNOWN evaluates to UNKNOWN and filters the row out.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.