Skip to content

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:

STATE = 'GA' AND POP > 50000
NAME LIKE 'A%' OR NAME LIKE 'B%'
NOT (LANDUSE = 'Industrial')

Precedence — the gotcha

In SQL, AND binds tighter than OR. So:

A = 1 AND B = 2 OR C = 3

Means:

(A = 1 AND B = 2) OR C = 3

And:

A = 1 OR B = 2 AND C = 3

Means:

A = 1 OR (B = 2 AND C = 3)

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"

STATE IN ('GA','FL','SC') AND POP > 100000

(Cleaner than STATE = 'GA' OR STATE = 'FL' OR STATE = 'SC'. → See IN Operator.)

"Either dense or large"

DENSITY > 1000 OR AREA_KM2 > 5000

"Industrial or commercial — but not vacant"

(LANDUSE = 'Industrial' OR LANDUSE = 'Commercial') AND VACANT = 'N'

"Title I elementary OR (any school with > 1000 enrollment)"

(TITLE1 = 'Y' AND LEVEL = 'Elementary')
  OR ENROLLMENT > 1000

NOT and negation

NOT lets you invert a condition:

NOT (STATE IN ('GA','FL'))
NOT (LANDUSE LIKE 'Res%')
NOT (POP > 100000)

But beware NULL: NOT (POP > 100000) excludes rows where POP is NULL (those rows are "unknown"). To include them:

NOT (POP > 100000) OR POP IS NULL

De Morgan's laws (useful)

These are equivalent:

NOT (A AND B)      (NOT A) OR (NOT B)
NOT (A OR B)       (NOT A) AND (NOT B)

So:

NOT (STATE = 'GA' AND POP > 100000)

(STATE <> 'GA') OR (POP <= 100000)

Building complex queries step by step

When a query gets complex:

  1. Write the simplest condition first in Select by Attributes. Note the count.
  2. Add the next condition with AND. Verify count goes down.
  3. 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:

   STATE      IN ('GA', 'FL', 'SC')
AND POP       > 100000
AND LANDUSE   LIKE 'Res%'
AND BUILT_YR  >= 1980

ArcGIS Pro accepts whitespace and newlines in the SQL editor.


Practice

Predict the count

Counties layer with STATE, POP2020, LANDUSE. Predict roughly:

  1. STATE = 'GA' AND POP2020 > 100000
  2. STATE = 'GA' OR POP2020 > 1000000
  3. (STATE = 'GA' OR STATE = 'FL') AND POP2020 > 50000
  4. NOT (STATE = 'GA') AND POP2020 > 100000

Run each. Compare your prediction.

→ Next: IN Operator.