LIKE Operator¶
Goal: Match text by pattern using
LIKEand wildcards.
Wildcards¶
| Wildcard | Matches |
|---|---|
% | Zero or more characters |
_ | Exactly one character |
Examples:
NAME LIKE 'A%' -- starts with A
NAME LIKE '%ville' -- ends with "ville"
NAME LIKE '%ville%' -- contains "ville" anywhere
NAME LIKE 'A_lanta' -- A, any single char, lanta → "Atlanta"
NAME LIKE '____' -- exactly 4 characters
Esri's older style used * and ?
Older ArcGIS docs reference * and ? as wildcards. In modern ArcGIS Pro with file geodatabases, use % and _ (SQL standard). Pro auto-translates in some places, but writing the SQL standard is safer.
Case sensitivity¶
Depends on the data source:
| Source | Default |
|---|---|
| File geodatabase | Case-sensitive |
| Shapefile | Case-sensitive |
| SQL Server | Usually case-insensitive |
| PostgreSQL | Case-sensitive (use ILIKE for insensitive) |
To make file-gdb queries case-insensitive:
NOT LIKE¶
Escaping the wildcards¶
If you need to match a literal % or _, use the ESCAPE clause:
DESC LIKE '50\%' ESCAPE '\' -- match the literal "50%"
NAME LIKE 'a\_b' ESCAPE '\' -- match "a_b" exactly
Practical patterns¶
| Pattern | Use case |
|---|---|
'St %' | Starts with "St " (saint streets) |
'%St' | Ends with "St" |
'% Inc.' | Ends with " Inc." |
'Atl%' | "Atlanta", "Atlas", "Atlantic"… |
'%@gmail.com' | Gmail addresses |
'404-%-____' | "404-XXX-XXXX" phone format |
'%[0-9]%' | (Some dialects only) — contains a digit |
Combining with other conditions¶
NAME LIKE 'A%' AND POP > 50000
NAME LIKE '%ville' OR NAME LIKE '%burg'
COUNTY = 'Fulton' AND ADDRESS LIKE '%Peachtree%'
A common gotcha¶
LIKE without a wildcard behaves exactly like =. Probably not what you want.
Performance note¶
LIKE 'A%' (anchored at the start) can use an index → fast.
LIKE '%ville' (wildcard at the start) cannot use an index → slow on big tables. For huge enterprise databases, consider full-text indexes.
Practice¶
Try these
Counties layer:
- Counties starting with "M" →
NAME LIKE 'M%' - Counties ending with "County" (most do) →
NAME LIKE '%County' - Counties containing "land" →
NAME LIKE '%land%' - 4-letter county names →
NAME LIKE '____' - Not starting with a vowel →
NAME NOT LIKE 'A%' AND NAME NOT LIKE 'E%' AND NAME NOT LIKE 'I%' AND NAME NOT LIKE 'O%' AND NAME NOT LIKE 'U%'
→ Next: AND / OR.