Part 15: Logical Operators: AND, OR & NOT (Precedence Rules)

Part 15 Technology Updated September 12, 2026

Part 15: Logical Operators: AND, OR & NOT (Precedence Rules)

Combining multiple conditions requires understanding operator precedence.


1. Operator Precedence Trap

Critical Rule: In SQL, AND takes precedence over OR (just like multiplication takes precedence over addition in arithmetic).

-- What you might think this does: Employees in (HR or Sales) earning > 70000
-- What SQL actually executes: HR employees OR (Sales employees earning > 70000)
SELECT * FROM employees
WHERE department = 'HR' OR department = 'Sales' AND salary > 70000;

--  CORRECT: Always use explicit parentheses!
SELECT * FROM employees
WHERE (department = 'HR' OR department = 'Sales') AND salary > 70000;

Key Takeaways

  • AND is evaluated before OR.
  • Always wrap conditions in explicit parentheses () to avoid subtle logical bugs.

In Part 16, we explore Range Filtering with BETWEEN and NOT BETWEEN!