SQL LIKE and wildcards
LIKE matches text against a pattern. % stands for any number of characters, including none, and _ stands for exactly one character.
What do the patterns match?
| Pattern | Matches |
|---|---|
'A%' | starts with A |
'%son' | ends with son |
'%data%' | contains data |
'_a%' | a as the second letter |
'____' | exactly four characters |
Is LIKE case-sensitive?
It depends on the database. SQLite and MySQL ignore case for plain letters by default, PostgreSQL does not (it has ILIKE for that). To be safe everywhere:
WHERE LOWER(email) LIKE '%@gmail.com'
How do you search for a real % or _?
Use an escape character:
WHERE code LIKE '%10\%%' ESCAPE '\'
Common mistakes
LIKE 'data' without wildcards only matches exactly "data". A pattern that starts with % can't use an index, so it is slow on big tables.
Try it yourself. Practise this in a real database in your browser, with instant feedback.
Practise LIKE
Practise LIKE
Updated November 2026.