0PricingLogin
SQL Interview Prep · Lesson

AND/OR Precedence and Parenthesization

The single most common filtering bug interviewers plant in their questions.

The Trap Interviewers Plant

The single most common filtering bug in interviews looks correct at a glance. You are asked: find orders from customer 5 that are either pending or shipped. A candidate writes a WHERE with AND and OR mixed together and gets extra rows back.

Why? Because AND binds tighter than OR. The database evaluates all the AND pairs first, then the ORs. This lesson makes that rule reflexive so you never lose points on it.

Operator Precedence in One Sentence

In every SQL dialect, the logical operators bind in this order: NOT first, then AND, then OR last.

  • NOT is highest precedence
  • AND is middle
  • OR is lowest

So A OR B AND C is read as A OR (B AND C), never (A OR B) AND C. The interviewer is counting on you forgetting this.

All lessons in this course

  1. AND/OR Precedence and Parenthesization
  2. BETWEEN, IN, and Inclusive Boundaries
  3. LIKE, Wildcards and Escaping
  4. Filtering on Calculated Values
← Back to SQL Interview Prep