OR Operator
Match rows where at least one condition is true
OR: At Least One Condition Must Be True
OR combines conditions and requires at least one to be true. Unlike AND which narrows results, OR broadens them — any row matching at least one condition is included. Here's what to know:
category = 'Electronics' OR category = 'Furniture' AND price > 100 reads as Electronics OR (Furniture AND price > 100) — almost certainly not what you intended to write.(category = 'Electronics' OR category = 'Furniture') AND price > 100 makes the grouping explicit. The OR resolves first, then AND applies to the combined result correctly.WHERE country IN ('India', 'Japan', 'Australia') is far cleaner and easier to read than chaining three separate OR conditions together.How OR Works
At least one condition must be true
- OR broadens results — more conditions = more rows
- Only ONE condition needs to be TRUE for inclusion
- OR has lower precedence than AND
- Often replaceable with IN for cleaner syntax
OR Gotchas
Mixing AND with OR is the #1 trap
a AND b OR cmeans(a AND b) OR c— nota AND (b OR c)- Always use parentheses when mixing AND and OR
- Multiple ORs on same column → use IN instead
- OR can prevent index usage — watch for full table scans
OR vs IN
When to use which
country = 'IN' OR country = 'US'country IN ('IN', 'US')OR Truth Table
Quick reference
- TRUE OR FALSE → TRUE
- FALSE OR FALSE → FALSE
- TRUE OR NULL → TRUE
- FALSE OR NULL → NULL (excluded)
ORAt least one condition must be true( )ALWAYS use parentheses when mixing AND and OR| id | customer_id | status | total |
|---|---|---|---|
| 5001 | C1001 | delivered | 59.98 |
| 5002 | C1002 | delivered | 449 |
| 5003 | C1001 | shipped | 12.5 |
| 5004 | C1003 | delivered | 89.99 |
| 5005 | C1006 | pending | 245 |
| 5006 | C1005 | delivered | 159 |
| 5007 | C1004 | shipped | 45.5 |
| 5008 | C1009 | cancelled | 79 |
| 5009 | C1012 | delivered | 425 |
| 5010 | C1007 | pending | 18.99 |
| 5011 | C1008 | delivered | 134 |
| 5012 | C1010 | cancelled | 65.5 |
| id | name | category | price | stock |
|---|---|---|---|---|
| P101 | Wireless Mouse | Electronics | 24.99 | 150 |
| P102 | Office Desk | Furniture | 189 | 25 |
| P103 | LED Desk Lamp | Furniture | 45.5 | 80 |
| P104 | USB-C Cable | Electronics | 12.99 | 500 |
| P105 | Bluetooth Speaker | Electronics | 79 | 60 |
| P106 | Office Chair | Furniture | 95 | 15 |
| P107 | Coffee Maker | Appliances | 89.99 | 40 |
| P108 | Notebook Set | Stationery | 8.5 | 200 |
| P109 | Wireless Headphones | Electronics | 159 | 30 |
| P110 | Standing Desk | Furniture | 425 | 8 |
Worked Example
Find all orders that are either 'pending' or 'shipped'.
| id | status | total |
|---|---|---|
| 5003 | shipped | 12.5 |
| 5005 | pending | 245 |
| 5007 | shipped | 45.5 |
| 5010 | pending | 18.99 |
Mixing AND/OR without parentheses
This is read as: Electronics OR (Furniture AND price > 100). All electronics pass regardless of price — not the intended behavior.
Use parentheses: WHERE (category = 'Electronics' OR category = 'Furniture') AND price > 100
Key Concepts
Pro Tip
OR lets you match multiple alternatives. Combined with AND and parentheses, you can express arbitrarily complex filters.
When to Use
Orders that are pending or shipped, customers from selected countries, products in multiple categories.
Find all products that are either in 'Electronics' or 'Furniture' category AND cost more than 30. Use parentheses correctly.