SQL Tutorial · SQL Basics · Lesson 8 of 36
SQL LIKE and Wildcards
Match text patterns with LIKE, % and _.
LIKE
LIKE matches text against a pattern with two wildcards:
| Wildcard | Matches |
|---|---|
% |
any sequence of characters (including none) |
_ |
exactly one character |
SELECT name FROM customers WHERE name LIKE 'A%';
SELECT email FROM customers WHERE email LIKE '%[email protected]';
SELECT name FROM products WHERE name LIKE '%desk%';
SELECT name FROM products WHERE name LIKE '_SB%';
Output
name Ada Lovelace Alan Turing email [email protected] [email protected] name Desk Lamp Standing Desk Mat name USB-C Hub
Case sensitivity
In SQLite and MySQL, LIKE is case-insensitive for ASCII letters by default. In PostgreSQL it's case-sensitive — use ILIKE there for case-insensitive matching.
A pattern that starts with % can't use a normal index, so LIKE '%term%' on a big table is slow. Use full-text search for real search features.
Test yourself
Which wildcard matches exactly one character?
%_*?
Show answer
Answer: _