iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

SQL LIKE

LIKE matches text against a simple pattern. Two wildcards do all the work: % (any string) and _ (any single character).

Wildcards

PatternMatches
'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.
  • PostgreSQLLIKE is case-sensitive; use ILIKE for 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

Example
SELECT * FROM customers
WHERE name LIKE 'A%';
Try it Yourself »

Exercise

Find names that start with the letter A.

WHERE name LIKE 'A '

Test yourself

Q1. % in LIKE matches…
Q2. _ in LIKE matches…
Q3. Postgres case-insensitive LIKE is…

Discussion

Loading…