AND Operator

Require multiple conditions to all be true at once

Beginner 10 minANDfilteringlogic

AND: All Conditions Must Be True

AND combines multiple conditions in a WHERE clause and requires all of them to be true. If even one condition fails, the row is excluded from the result. Here's what makes AND essential:

AND narrows your results — Each additional AND makes the filter stricter. "Electronics" might return 5 rows, "Electronics AND price < 50" narrows it to 2, and adding "AND stock > 100" might narrow it down to just 1 result row.
Chain as many as needed — SQL lets you combine any number of AND conditions in a single query. The optimizer may reorder them for performance, but the logical result always stays identical regardless of order.
Precedence matters — AND binds tighter than OR. The expression A OR B AND C evaluates as A OR (B AND C) — not (A OR B) AND C. Always use parentheses to make your intent clear and avoid subtle logic bugs.
Knowledge Canvas

How AND Works

Both conditions must be true

  • AND narrows results — more conditions = fewer rows
  • All conditions must evaluate to TRUE for the row to appear
  • AND has higher precedence than OR
  • Chain as many AND conditions as needed

AND Gotchas

Subtle traps with AND

  • AND with NULL: TRUE AND NULL → NULL (row excluded)
  • Over-filtering: too many ANDs can return zero rows
  • Mixing AND and OR without parentheses changes meaning
  • WHERE a = 1 AND a = 2 always returns nothing

Rules to Remember

AND logic truth table

  • TRUE AND TRUE → TRUE
  • TRUE AND FALSE → FALSE
  • TRUE AND NULL → NULL (excluded)
  • FALSE AND NULL → FALSE

Common Patterns

How AND is used in practice

  • Date ranges: date >= '2024-01-01' AND date < '2025-01-01'
  • Multi-column filter: country = 'IN' AND status = 'active'
  • Null-safe: col IS NOT NULL AND col > 0
  • Combined with OR: (a OR b) AND c
Syntax
Syntax Template
1SELECT
2 columns
3FROM table
4WHERE condition1
5 AND condition2
6 AND condition3;
ANDALL conditions must be true
PrecedenceAND binds tighter than OR — use parentheses when mixing
Sample Data
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
orders
12 rows
idstatustotal
5001delivered59.98
5002delivered449
5003shipped12.5
5004delivered89.99
5005pending245
5006delivered159
5007shipped45.5
5008cancelled79
5009delivered425
5010pending18.99
5011delivered134
5012cancelled65.5

Worked Example

Find electronics that cost under 60 and have more than 100 units in stock.

SQL
1SELECT
2 name,
3 price,
4 stock
5FROM products
6WHERE category = 'Electronics'
7 AND price < 60
8 AND stock > 100;
Three conditions must ALL be true: the product must be in Electronics, priced under 60, and have stock exceeding 100. The Wireless Mouse (24.99, 150 stock) and USB-C Cable (12.99, 500 stock) satisfy all three. Bluetooth Speaker (79.00) fails the price check, and Wireless Headphones (159.00) fail it too.
Output
2 rows
namepricestock
Wireless Mouse24.99150
USB-C Cable12.99500

Key Concepts

1Every additional AND makes the filter stricter
2AND has higher precedence than OR — parentheses prevent bugs
3The database may reorder ANDs for performance — same result either way
4No limit on how many ANDs you can chain

Pro Tip

Most real queries need multiple conditions. AND is how you say "rows that satisfy ALL of these criteria simultaneously."

When to Use

Delivered orders from last month, active users in a specific region, products that are both in-stock and on sale.

Challenge

Solve the problem below

Find all orders (from the orders table) with status 'delivered' and total greater than 50. Show id, status, and total.

Your Query