SQL LIKE
LIKE matches text against a simple pattern. Two wildcards do all the work: % (any string) and _ (any single character).
Wildcards
| Pattern | Matches |
|---|---|
'A%' | Starts with A. |
'%berg' | Ends with "berg". |
'%love%' | Contains "love" anywhere. |
'A__a' | Starts with A, exactly two characters, then "a" — "Anna", "Aria", … |
'2026-%' | Any date string in 2026. |
Case sensitivity
- MySQL — case-insensitive by default for non-binary columns.
- SQL Server / SQLite — depends on the column's collation.
- PostgreSQL —
LIKEis case-sensitive; useILIKEfor case-insensitive.
Escaping a literal % or _
SQL
-- Find rows where name literally contains 50% SELECT * FROM products WHERE name LIKE '%50\%%' ESCAPE '\';
Tip: Patterns that start with
% can't use a normal B-tree index — they force a full scan. If you need fast contains-search, consider a full-text index.Example
Exercise
Find names that start with the letter A.
WHERE name LIKE 'A
'
A single wildcard for "any string".
Discussion
Loading…