AND requires every condition to be true. OR requires at least one to be true. Combining them without parentheses is the single biggest source of filtering bugs in SQL.
Syntax
WHERE condition1 AND condition2
WHERE condition1 OR condition2
Sample Table: employees
| name | department | salary |
|---|---|---|
| Aman | Engineering | 65000 |
| Riya | Marketing | 52000 |
| Karan | Engineering | 71000 |
| Neha | Design | 48000 |
AND Example
SELECT name FROM employees
WHERE department = 'Engineering' AND salary > 60000;
Output: Aman, Karan — both conditions must hold.
OR Example
SELECT name FROM employees
WHERE department = 'Design' OR salary > 60000;
Output: Aman, Karan, Neha — any row matching either condition qualifies.
The Parentheses Trap
AND binds tighter than OR — mixing them without parentheses often doesn't do what you'd expect:
-- Ambiguous intent, relies on AND-before-OR precedence
SELECT name FROM employees
WHERE department = 'Engineering' AND salary > 60000 OR department = 'Design';
-- What it ACTUALLY means:
WHERE (department = 'Engineering' AND salary > 60000) OR department = 'Design';
If the intent was "Engineering employees who either earn over 60,000 OR are in Design," that query is wrong — every Design employee gets included regardless of salary, because OR is evaluated at the top level. Always use explicit parentheses when mixing AND and OR:
WHERE department = 'Engineering' AND (salary > 60000 OR department = 'Design');
Common Mistakes
- Mixing
AND/ORwithout parentheses and getting silently wrong results (no error — just the wrong rows) - Writing
WHERE department = 'Engineering' OR 'Design'— invalid; each side ofORneeds its own full condition:department = 'Engineering' OR department = 'Design'(or use IN)
Interview Relevance
Interviewers often deliberately give you a filter with three or more conditions to see if you reach for parentheses instead of guessing at operator precedence.
Practice Question
Write a query for employees who are either in Engineering with a salary above 60,000, or in Marketing with a salary above 50,000 — using explicit parentheses.