SQLite GLOB Operator
The GLOB Operator
GLOB searches for a pattern, like LIKE. This is how they are different:
| LIKE | GLOB | |
|---|---|---|
| Upper and lower case | Does not matter: 'a%' also finds "Alfreds Futterkiste" | Matters: 'a*' does not find "Alfreds Futterkiste" |
| Any number of characters | % | * |
| Exactly one character | _ | ? |
| One of several characters | Not possible | [abc] |
The GLOB wildcards are the same as the ones used for file names on the command line.
This example selects all the customers whose name starts with a capital "A":
These are the wildcards you can use with GLOB:
| Wildcard | Means |
|---|---|
* | Zero, one or many characters |
? | Exactly one character |
[abc] | One of the characters a, b or c |
[a-z] | One character in the range a to z |
[^abc] | One character that is not a, b or c |
Upper and Lower Case
No customer name starts with a small "a", so this example returns no records:
With LIKE, the same kind of pattern finds the customers whose name starts with "A", because LIKE does not care about upper and lower case:
The ? Wildcard
Example
Select the customers in a city that is any character, followed by "ondon":
SELECT * FROM Customers
WHERE City GLOB '?ondon';
Try it Yourself »
Character Lists
Example
Select the customers in a city that starts with "B", "S" or "P":
SELECT * FROM Customers
WHERE City GLOB '[BSP]*';
Try it Yourself »
Example
Select the customers whose name starts with a letter from "A" to "C":
SELECT * FROM Customers
WHERE CustomerName GLOB '[A-C]*';
Try it Yourself »
Not in the List
Example
Select the customers in a city that does not start with "B", "S" or "P":
SELECT * FROM Customers
WHERE City GLOB '[^BSP]*';
Try it Yourself »