AND Operator
SQL · Filtering Rows
Theory
AND combines two conditions and is TRUE only when both are TRUE. WHERE dept = 'IT' AND salary > 80000 keeps employees who are in IT and also earn more than ₹80,000; a row failing either test is removed. You can chain any number of conditions with AND, and each one narrows the result further.
With NULLs, AND follows three-valued logic: FALSE AND anything is FALSE, TRUE AND UNKNOWN is UNKNOWN, so the row is dropped. AND has higher precedence than OR, which means a OR b AND c is read as a OR (b AND c). Use parentheses whenever you mix the two. Many engines can stop evaluating once one side is FALSE, but the order is not guaranteed, so do not rely on short-circuiting to avoid errors.
Why we use it
Real questions usually have several requirements at once: a department and a salary range, a city and a date. AND lets you state all of them in one filter so only rows meeting every rule survive.
When to use it
Use AND when every condition must hold. If any one condition is enough, use OR or IN. When mixing AND with OR, wrap the OR part in parentheses so the logic is explicit.
How it works
- Read a row
- Evaluate the first condition
- Is it TRUE? Yes: Evaluate the next condition. No: Row fails: discard it.
- Are all conditions TRUE? Yes: Keep the row. No: Discard the row.
- Move to the next row
Syntax
SELECT columns FROM table
WHERE cond1 AND cond2;Example
SELECT * FROM employees WHERE department = 'IT' AND salary > 50000;Key points
- All joined conditions must evaluate TRUE
- Each extra AND can only shrink the result
- AND binds tighter than OR; use parentheses when mixing them
- TRUE AND UNKNOWN (NULL) is UNKNOWN, so the row is dropped
- Order of conditions does not change the result