Filtering & predicates
Concept  ·  SQL & Querying

AND binds tighter than OR — missing parentheses change which rows match.

The parser has one precedence table and your intuition has another — spoken English overloads 'or' and 'and' with grouping the listener infers, SQL infers nothing. The failure is maximally quiet: more rows, all individually plausible, filtered report slightly wrong forever. Two disciplines end it: parentheses on every mixed OR/AND, and IN lists for the any-of-these half.

See it break
tix
idzoneday
1lawnsat
2lawnsun
3vipsat
4vipsun
The trap
SELECT
  id
FROM
  tix
WHERE
  zone = 'lawn'
    OR zone = 'vip'
  AND day = 'sat'
ORDER BY
  id;
The fix
SELECT
  id
FROM
  tix
WHERE
  (
    zone = 'lawn'
    OR zone = 'vip'
  )
  AND day = 'sat'
ORDER BY
  id;
The trap
1
2
3
The fix
1
3

The Saturday report included Sunday lawn tickets — AND binds tighter than OR, so 'lawn OR vip AND sat' parsed as 'lawn OR (vip AND sat)', leaking every lawn day in.

The rule

Parenthesize every mixed OR/AND predicate, and reshape the OR half into an IN list (zone IN ('lawn','vip') AND day='sat').

Shows up elsewhere
WHERE keeps only TRUEImplicit casts in comparisons
Try one →Prove it in practice →