Lesson 01 used WHERE col = value and stopped there. The real power of WHERE is the predicate vocabulary on the right-hand side. This lesson is a tour of the operators you'll reach for every day.
The seed loaded a users table similar to before, plus a nullable country column and a few extra people — sixteen rows in total.
Comparisons beyond =
The usual suspects work how you'd expect: <, <=, >, >=, <> (or !=).
SELECT full_name, signed_up_at
FROM users
WHERE signed_up_at >= '2024-06-01';
<> and != are interchangeable in Postgres, but the SQL standard spells it <>. Pick one and stay consistent.
Combine predicates with AND / OR
AND binds tighter than OR, just like * binds tighter than + in arithmetic. When in doubt, parenthesize.
SELECT full_name, country, is_active
FROM users
WHERE is_active = true
AND (country = 'US' OR country = 'UK');
Without those parentheses, the query reads as is_active = true AND country = 'US' or country = 'UK' — which would happily include inactive UK users. Parentheses are documentation as much as logic.
IN is a friendlier OR
When you'd be OR-ing the same column against a list of values, IN is cleaner.