AND, OR, NOT Operators
The AND, OR, and NOT operators combine or negate conditions in the WHERE clause.
💡 These logical operators let you build complex filters by combining multiple conditions.
AND Operator
Returns TRUE if all conditions are TRUE.
SELECT first_name, last_name, salary, department
FROM employees
WHERE department = 'Engineering' AND salary > 70000;
OR Operator
Returns TRUE if any condition is TRUE.
SELECT first_name, last_name, department
FROM employees
WHERE department = 'Engineering' OR department = 'Sales';
NOT Operator
Negates a condition.
SELECT first_name, last_name, department
FROM employees
WHERE NOT department = 'Engineering';
Operator Precedence
-- Order: NOT → AND → OR
-- Use parentheses for clarity:
SELECT * FROM employees
WHERE (department = 'Engineering' OR department = 'Sales')
AND salary > 80000;
✅ Key Takeaways
- AND — all conditions must be TRUE
- OR — any condition must be TRUE
- NOT — negates a condition
- Precedence: NOT > AND > OR
- Use parentheses to make precedence clear