AND Operator
Require multiple conditions to all be true at once
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:
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.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 = 2always 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
ANDALL conditions must be truePrecedenceAND binds tighter than OR — use parentheses when mixing| 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 |
| id | status | total |
|---|---|---|
| 5001 | delivered | 59.98 |
| 5002 | delivered | 449 |
| 5003 | shipped | 12.5 |
| 5004 | delivered | 89.99 |
| 5005 | pending | 245 |
| 5006 | delivered | 159 |
| 5007 | shipped | 45.5 |
| 5008 | cancelled | 79 |
| 5009 | delivered | 425 |
| 5010 | pending | 18.99 |
| 5011 | delivered | 134 |
| 5012 | cancelled | 65.5 |
Worked Example
Find electronics that cost under 60 and have more than 100 units in stock.
| name | price | stock |
|---|---|---|
| Wireless Mouse | 24.99 | 150 |
| USB-C Cable | 12.99 | 500 |
Key Concepts
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.
Find all orders (from the orders table) with status 'delivered' and total greater than 50. Show id, status, and total.