IN Operator¶
Goal: Use
INto match a list of values cleanly.
The basics¶
IN is just shorthand for many ORs:
Equivalent to:
IN is more readable, especially with long lists.
With numbers¶
With NOT IN¶
This excludes those states. Same gotcha as before — rows where STATE IS NULL are also excluded, because the comparison is "unknown" for NULLs.
NULL inside IN¶
IN (..., NULL) doesn't do what you think:
NULL doesn't compare with =. Always use OR ... IS NULL separately.
Real GIS examples¶
Filtering states¶
Filtering land use codes¶
Filtering by precincts¶
Excluding sensitive areas¶
With subqueries (full SQL only)¶
In real SQL (not ArcGIS Pro Select by Attributes), IN accepts a sub-query:
ArcGIS Pro Select by Attributes does not support sub-queries. Workaround:
- First selection: get the list of
zone_idvalues manually or with a separate analysis. - Use those values in an
INlist.
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:
LEVEL = 'Elementary' OR LEVEL = 'Middle' OR LEVEL = 'High'STATUS = 'Open' OR STATUS = 'Pending'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.