AND, OR, NOT
AND, OR, and NOT help you combine conditions.
Use AND when every condition must be true.
Use OR when at least one condition can be true.
Use NOT when you want to exclude a condition.
Example with OR:
SELECT * FROM `prj-training-ao7c.voterfiles.voterfile_snapshot` WHERE gender = 'Female' OR vb_voterbase_age_bucket = '18-29' ORDER BY gender;
This query returns rows where the person is listed as female or where the age bucket is 18-29. It is broader because either condition can qualify the row.
Example with AND:
SELECT * FROM `prj-training-ao7c.voterfiles.voterfile_snapshot` WHERE gender = 'Female' AND vb_voterbase_age_bucket = '30-39' ORDER BY urbanicity;
This query is narrower. It returns only rows where both conditions are true: the gender value is female and the age bucket is 30-39.
Parentheses can help when you combine multiple conditions:
WHERE (source = 'survey' OR source = 'event') AND signup_date >= '2026-04-01'
Parentheses make your intent clear. They also prevent BigQuery from interpreting mixed logic in a way you did not expect.
Learner action
Write two versions of your filter:
- A broader version using
OR. - A narrower version using
AND.
Which one better matches your organizing decision?
From the deck (slide 38):
AND: returns TRUE only if all conditions are true. Use it to narrow.OR: returns TRUE if any condition is true. Use it to broaden.NOT: negates the condition that follows.
Here is the deck's side-by-side example. Same table, very different results.
Query A : broader (uses OR)
SELECT * FROM `prj-training-ao7c.voterfiles.voterfile_snapshot` WHERE gender = 'Female' OR vb_voterbase_age_bucket = '18-29' ORDER BY gender;
Returns: every female voter, plus every voter (regardless of gender) in the 18–29 bucket. Sorted alphabetically by gender.
Query B : narrower (uses AND)
SELECT * FROM `prj-training-ao7c.voterfiles.voterfile_snapshot` WHERE gender = 'Female' AND vb_voterbase_age_bucket = '30-39' ORDER BY urbanicity;
Returns: only female voters who are also in the 30–39 bucket. Sorted by urbanicity (urban / suburban / rural).
The #1 logic bug
Picking OR when you meant AND, or vice versa. Read your query out loud in plain English first: "I want rows where X and Y" vs "I want rows where X or Y." If the sentence doesn't match what you actually want, swap the operator.
Parentheses group conditions and control precedence. WHERE a OR b AND c is read by SQL as WHERE a OR (b AND c). If you meant (a OR b) AND c, add the parens.
AND, OR, NOT let you stack conditions. Parentheses control how they group : without them, AND binds tighter than OR. Try a real organizing question: “newly-registered Democrats in our two biggest counties.”
Action: Decide if your filter needs AND or OR. Write the second condition. Run it.