Blog · Guide

SQL AND vs OR: How Compound Filters Work

AND means both conditions must be true. OR means either can be. Parentheses save you when filters get messy.

all rows WHERE kept rows
WHERE keeps only the rows that match your condition.

AND = narrower result

SELECT first_name, city, age
FROM customers
WHERE city = 'Austin' AND age >= 30;

Both must match. Think: “Austin customers who are also 30+.”

OR = wider result

WHERE city = 'Austin' OR city = 'Chicago'

Either city is enough. When you mix AND and OR, use parentheses so the database doesn’t guess wrong about priority.

Try it yourself

The fastest way to lock this in is a short drill on the same Northstar Market tables.

Practice WHERE with AND

Related guides