Skip to content

IN Operator

Goal: Use IN to match a list of values cleanly.


The basics

IN is just shorthand for many ORs:

STATE IN ('GA', 'FL', 'SC')

Equivalent to:

STATE = 'GA' OR STATE = 'FL' OR STATE = 'SC'

IN is more readable, especially with long lists.

With numbers

DISTRICT IN (1, 2, 3, 7, 9)

With NOT IN

STATE NOT IN ('GA', 'FL', 'SC')

This excludes those states. Same gotcha as before — rows where STATE IS NULL are also excluded, because the comparison is "unknown" for NULLs.

STATE NOT IN ('GA','FL','SC') OR STATE IS NULL    -- include unknowns

NULL inside IN

IN (..., NULL) doesn't do what you think:

STATE IN ('GA', NULL)        -- ⚠ won't match rows where STATE IS NULL

NULL doesn't compare with =. Always use OR ... IS NULL separately.

Real GIS examples

Filtering states

STATE_NAME IN ('Georgia', 'Florida', 'South Carolina', 'North Carolina')

Filtering land use codes

LANDUSE_CODE IN (110, 120, 130, 140)

Filtering by precincts

PRECINCT IN ('A1','A2','B3')

Excluding sensitive areas

ZONE NOT IN ('Wetland','Floodway','Conservation')

With subqueries (full SQL only)

In real SQL (not ArcGIS Pro Select by Attributes), IN accepts a sub-query:

SELECT *
FROM   parcels
WHERE  zone_id IN (
    SELECT id FROM zones WHERE protected = TRUE
);

ArcGIS Pro Select by Attributes does not support sub-queries. Workaround:

  1. First selection: get the list of zone_id values manually or with a separate analysis.
  2. Use those values in an IN list.

Or use arcpy.da.SearchCursor in Python.

Performance

IN with a small list is just as fast as a few ORs. But IN with hundreds of values can slow down — at that point, prefer a join with a lookup table (or use a Python script).


Practice

Replace OR with IN

Rewrite these using IN:

  1. LEVEL = 'Elementary' OR LEVEL = 'Middle' OR LEVEL = 'High'
  2. STATUS = 'Open' OR STATUS = 'Pending'
  3. DISTRICT = 1 OR DISTRICT = 2 OR DISTRICT = 5 OR DISTRICT = 8

Answers: 1) LEVEL IN ('Elementary','Middle','High') 2) STATUS IN ('Open','Pending') 3) DISTRICT IN (1, 2, 5, 8)

→ Next: IS NULL.