Combining conditions with AND and OR
Join conditions with AND when every one must be true, and OR when any one will do:
SELECT name, city
FROM customers
WHERE customer_type = 'Business' AND region = 'Scotland'Brackets matter
AND is worked out before OR, just as × comes before + in arithmetic. This query is a common
trap:
-- Not what it looks like!
WHERE category = 'Furniture' OR category = 'Writing' AND list_price < 5It means "all Furniture, plus Writing products under £5". To apply the price limit to both categories, use brackets:
WHERE (category = 'Furniture' OR category = 'Writing') AND list_price < 5When you mix AND and OR, always add brackets, even when you think they aren't needed. It makes
your intention clear.