SQLite LIKE Operator
The LIKE Operator
LIKE is used in a WHERE clause to search for a pattern in a column.
There are two wildcards you can use with LIKE:
- The percent sign
%means zero, one or many characters - The underscore sign
_means exactly one character
This example selects all the customers whose name starts with "a":
Upper and Lower Case
In SQLite, LIKE does not care about upper and lower case for the letters A to Z. That is why 'a%' above also finds names that start with a capital A.
Tip: To search with case sensitivity, use GLOB. Read more in the SQLite GLOB chapter.
The _ Wildcard
The _ wildcard matches exactly one character. This example selects the customers in a city that starts with "L", then any character, then "nd", then two more characters:
The % Wildcard
The % wildcard matches any number of characters, even zero. This example selects the customers in a city that contains the letter "L":
Starts With
Example
Select the customers whose name starts with "La":
SELECT * FROM Customers
WHERE CustomerName LIKE 'La%';
Try it Yourself »
Ends With
Example
Select the customers whose name ends with "a":
SELECT * FROM Customers
WHERE CustomerName LIKE '%a';
Try it Yourself »
Contains
Example
Select the customers whose name contains "or":
SELECT * FROM Customers
WHERE CustomerName LIKE '%or%';
Try it Yourself »
Combine Wildcards
This example selects the customers whose name starts with "a" and is at least three characters long:
Without Wildcards
Without wildcards, LIKE works like =, except that upper and lower case do not matter: