AND / OR¶
Goal: Combine multiple conditions confidently — without falling into the operator-precedence trap.
The basics¶
condition1 AND condition2 -- both must be true
condition1 OR condition2 -- either is true
NOT condition -- inverse
Examples:
Precedence — the gotcha¶
In SQL, AND binds tighter than OR. So:
Means:
And:
Means:
This trips up almost everyone. Always use parentheses when mixing.
With parentheses¶
(STATE = 'GA' OR STATE = 'FL') AND POP > 100000
-- vs.
STATE = 'GA' OR (STATE = 'FL' AND POP > 100000)
These return very different results. Be explicit.
Common patterns¶
"In any of these states, with high population"¶
(Cleaner than STATE = 'GA' OR STATE = 'FL' OR STATE = 'SC'. → See IN Operator.)
"Either dense or large"¶
"Industrial or commercial — but not vacant"¶
"Title I elementary OR (any school with > 1000 enrollment)"¶
NOT and negation¶
NOT lets you invert a condition:
But beware NULL: NOT (POP > 100000) excludes rows where POP is NULL (those rows are "unknown"). To include them:
De Morgan's laws (useful)¶
These are equivalent:
So:
Building complex queries step by step¶
When a query gets complex:
- Write the simplest condition first in Select by Attributes. Note the count.
- Add the next condition with AND. Verify count goes down.
- Add OR conditions wrapped in parens. Verify count goes up.
This avoids debugging a 5-condition query that returns zero rows.
Style: format for readability¶
A clean format makes complex queries readable:
ArcGIS Pro accepts whitespace and newlines in the SQL editor.
Practice¶
Predict the count
Counties layer with STATE, POP2020, LANDUSE. Predict roughly:
STATE = 'GA' AND POP2020 > 100000STATE = 'GA' OR POP2020 > 1000000(STATE = 'GA' OR STATE = 'FL') AND POP2020 > 50000NOT (STATE = 'GA') AND POP2020 > 100000
Run each. Compare your prediction.
→ Next: IN Operator.