Lesson 4 / 37 · Conditions and NULL

AND is evaluated before OR

AND binds tighter than OR, the way × binds tighter than +. The database reads this WHERE as status = 'paid' OR (status = 'refunded' AND amount > 100), and the condition column shows those hidden parentheses: the amount is only checked for refunded orders.

The query

SELECT id, status, amount
FROM orders
WHERE status = 'paid' OR status = 'refunded' AND amount > 100

Write (status = 'paid' OR status = 'refunded') AND amount > 100: the count drops to 5.

Next: IN, LIKE and BETWEEN are ordinary conditions · All lessons