Combining Conditions with AND, OR, and Parentheses
When a filter has multiple conditions, parentheses make your intent explicit.
AND
and
OR
let one
WHERE
clause check more than one thing. Use
AND
when every condition must be true. Use
OR
when any condition can be true.
Parentheses matter when you mix them. They show which conditions belong together, the same way they do in arithmetic.
select column_one, column_two
from table_name
where (condition_a or condition_b)
and condition_c Schema · Garden Shop Table · products 9 columns · 24 rows
One row per product, with price, cost, and inventory levels.
Show each product's product name, price, and quantity on hand when the product costs more than $20 or has fewer than 10 units on hand. Exclude discontinued products.
Run your query to inspect the result.
Expected answer
- Columns: product_name, price, quantity_on_hand.
- Rows: 11 products.
- No discontinued products should appear.
Related
Comparisons, AND/OR, IN, BETWEEN, and LIKE.
SELECT, WHERE, ORDER BY, and LIMIT at a glance.
Debug filters that match nothing.
Nested SELECTs, IN, EXISTS, and correlation.
UNION, UNION ALL, INTERSECT, and EXCEPT.
A stray NULL drops every row. Use NOT EXISTS.