SQL AND, OR and NOT

AND, OR and NOT combine conditions in WHERE. AND needs both sides to be true, OR needs either, and NOT flips a condition.

Updated December 1, 2026

Syntax

WHERE condition1 AND condition2
WHERE condition1 OR condition2
WHERE NOT condition

AND: every condition must match

Coffee that costs less than $4.50.

SELECT name, price
FROM drinks
WHERE category = 'coffee' AND price < 4.5;
Result on the SQL Café sample data (2 rows)
nameprice
Espresso3
Cappuccino4.25

Use parentheses with OR

AND binds tighter than OR, like multiplication before addition. Parentheses make sure the OR is checked first: here, caffeine-free drinks that are tea or “other”.

SELECT name, category
FROM drinks
WHERE (category = 'tea' OR category = 'other')
  AND caffeinated = 0;
Result on the SQL Café sample data (3 rows)
namecategory
Peppermint Teatea
Hot Chocolateother
Lemonadeother

NOT: exclude matches

NOT reverses a condition. It reads well with IN, LIKE and BETWEEN.

SELECT name, category
FROM drinks
WHERE NOT category = 'coffee';
Result on the SQL Café sample data (5 rows)
namecategory
Matcha Lattetea
Chai Lattetea
Peppermint Teatea
Hot Chocolateother
Lemonadeother

Common mistakes

Practice AND, OR and NOT interactively

Write real queries in your browser and get instant feedback in the lesson “AND, OR, NOT” (Unit 2). New learners can start free from the first lesson.

Frequently asked questions

Which runs first, AND or OR?

NOT first, then AND, then OR. Add parentheses whenever you mix AND and OR, even if you think the default is right.

Is there a shorter way to write many ORs?

Yes: category IN ('tea', 'other') means the same as two OR conditions. See IN.

Related SQL tutorials