AND joins two conditions and keeps a row only if both are true. Garden products under 30:
SELECT name, price
FROM products
WHERE category = 'Garden' AND price < 30;
Returns
name | price
------------+------
Duck feeder | 24
Pond net | 12.5
(2 rows)
OR keeps a row if either one is true (or both):
SELECT name, city
FROM customers
WHERE city = 'Boston' OR city = 'Denver';
Returns
name | city
-----+-------
Ben | Denver
Dev | Boston
Eve | Denver
Gus | Boston
(4 rows)
When you mix them, AND is worked out before OR, the way multiplying comes before adding in arithmetic. Put brackets around the part that should go together. Books or garden things, and in either case under 15:
SELECT name, category, price
FROM products
WHERE (category = 'Books' OR category = 'Garden') AND price < 15;
Returns
name | category | price
-----------+----------+------
Pond net | Garden | 12.5
Sketchbook | Books | 9.75
(2 rows)
Without the brackets, the database reads it as "Books, or Garden things under 15", and the field guide at 18 sneaks in. When you mix AND and OR, add brackets even when you think you don't need them.
IN is a short way to write several ORs on one column: city IN ('Boston', 'Denver') means the same as the OR query above. BETWEEN checks a range, and includes both ends:
SELECT name, price
FROM products
WHERE price BETWEEN 20 AND 50;