Module 02 · lesson 6
LIKE: pattern search
A user types "Coffee" into the site search. Exact equality isn't enough here — you need to find every name that contains this word.
Pattern search
LIKE searches text by a pattern with wildcard characters:
%— any sequence of characters (including an empty one);_— exactly one character of any kind.
SELECT name
FROM products
WHERE name LIKE 'S%'; -- name starts with "S"
Example patterns:
'%Wireless%'— contains "Wireless";'Run%'— starts with "Run";'%Card'— ends with "Card".
LIKE is case-sensitive. In PostgreSQL there's ILIKE — the same search but case-insensitive ('%sql%' will also find "SQL").
Your turn
The user is searching for "Coffee". Find all products whose name contains this word (output name).
Summary
%— any text,_— a single character.'Run%'— starts with;'%Wireless%'— contains.LIKEis case-sensitive;ILIKEisn't (Postgres).