OR Operator

Match rows where at least one condition is true

Beginner 10 minORfilteringlogic

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:

OR adds matching rows — Each additional OR condition includes more rows in the result. Useful for checking a column against several possible values in a single query without writing separate statements.
The precedence trap — AND binds tighter than OR. category = 'Electronics' OR category = 'Furniture' AND price > 100 reads as Electronics OR (Furniture AND price > 100) — almost certainly not what you intended to write.
Always use parentheses(category = 'Electronics' OR category = 'Furniture') AND price > 100 makes the grouping explicit. The OR resolves first, then AND applies to the combined result correctly.
For long lists, use IN — When checking against 3+ values, WHERE country IN ('India', 'Japan', 'Australia') is far cleaner and easier to read than chaining three separate OR conditions together.
Knowledge Canvas

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 c means (a AND b) OR c — not a 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

OR: flexible — any condition type
IN: only same-column equality checks
country = 'IN' OR country = 'US'
country IN ('IN', 'US')
Verbose with many values
Clean and readable with lists
Can combine different columns
Single column only

OR Truth Table

Quick reference

  • TRUE OR FALSE → TRUE
  • FALSE OR FALSE → FALSE
  • TRUE OR NULL → TRUE
  • FALSE OR NULL → NULL (excluded)
Syntax
Syntax Template
1WHERE condition1
2 OR condition2;
3
4-- Mix with AND using parentheses
5WHERE (cond1 OR cond2)
6 AND cond3;
ORAt least one condition must be true
( )ALWAYS use parentheses when mixing AND and OR
Sample Data
orders
12 rows
idcustomer_idstatustotal
5001C1001delivered59.98
5002C1002delivered449
5003C1001shipped12.5
5004C1003delivered89.99
5005C1006pending245
5006C1005delivered159
5007C1004shipped45.5
5008C1009cancelled79
5009C1012delivered425
5010C1007pending18.99
5011C1008delivered134
5012C1010cancelled65.5
products
10 rows
idnamecategorypricestock
P101Wireless MouseElectronics24.99150
P102Office DeskFurniture18925
P103LED Desk LampFurniture45.580
P104USB-C CableElectronics12.99500
P105Bluetooth SpeakerElectronics7960
P106Office ChairFurniture9515
P107Coffee MakerAppliances89.9940
P108Notebook SetStationery8.5200
P109Wireless HeadphonesElectronics15930
P110Standing DeskFurniture4258

Worked Example

Find all orders that are either 'pending' or 'shipped'.

SQL
1SELECT
2 id,
3 status,
4 total
5FROM orders
6WHERE status = 'pending'
7 OR status = 'shipped';
Each row is checked: is status 'pending'? If yes, include it. If no, is status 'shipped'? If yes, include it. If neither, exclude it. This gives us all non-delivered, non-cancelled orders.
Output
4 rows
idstatustotal
5003shipped12.5
5005pending245
5007shipped45.5
5010pending18.99
Common Mistakes

Mixing AND/OR without parentheses

SQL
1SELECT
2 *
3FROM products
4WHERE category = 'Electronics'
5 OR category = 'Furniture'
6 AND price > 100;

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

1OR broadens results — AND narrows them
2Always use parentheses when mixing OR with AND
3For 3+ value checks, prefer IN over chained ORs
4A OR B AND C means A OR (B AND C) — not (A OR B) AND C

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.

Challenge

Solve the problem below

Find all products that are either in 'Electronics' or 'Furniture' category AND cost more than 30. Use parentheses correctly.

Your Query