SQLite Wildcards
Wildcard Characters
A wildcard character stands for one or more other characters in a pattern.
SQLite has two operators that use wildcards, LIKE and GLOB, and they use different wildcards:
| Operator | Wildcard | Means | Example |
|---|---|---|---|
LIKE | % | Zero, one or many characters | 'bl%' finds bl, black, blue and blob |
LIKE | _ | Exactly one character | 'h_t' finds hot, hat and hit |
GLOB | * | Zero, one or many characters | 'bl*' finds bl, black, blue and blob |
GLOB | ? | Exactly one character | 'h?t' finds hot, hat and hit |
GLOB | [ ] | One of the characters in the brackets | 'h[oa]t' finds hot and hat, but not hit |
GLOB | [^ ] | One character that is not in the brackets | 'h[^oa]t' finds hit, but not hot and hat |
GLOB | - | A range of characters, inside brackets | '[a-c]*' finds everything that starts with a, b or c |
Using the % Wildcard
Example
Select the customers whose name ends with "es":
SELECT * FROM Customers
WHERE CustomerName LIKE '%es';
Try it Yourself »
Using the _ Wildcard
Example
Select the customers in a city that starts with any character, followed by "ondon":
SELECT * FROM Customers
WHERE City LIKE '_ondon';
Try it Yourself »
Using the [ ] Wildcard
LIKE has no [ ] wildcard in SQLite. Use GLOB instead. This example selects the customers in a city that starts with "B", "S" or "P":
Note: GLOB cares about upper and lower case. You will learn more in the next chapter.