LIKE
Matches text patterns using wildcards.
Overview
LIKE matches text patterns: % represents any sequence and _ represents one character. Use the database escape rules when the wildcard itself is literal. Case sensitivity depends on collation, and patterns that start with a wildcard may not use a normal index efficiently.
Basic syntax
SELECT * FROM orders WHERE name LIKE 'A%';
Examples
LIKE example
Use A% to find order names that begin with the letter A.
Sample table
Table:
orders| id | customer_id | product_id | name | department | amount | status | created_at | discount |
|---|---|---|---|---|---|---|---|---|
| 1 | 101 | 201 | Alice | Sales | 1200 | paid | 2026-01-03 | 0 |
| 2 | 102 | 202 | Bob | IT | 900 | pending | 2026-01-08 | 50 |
| 3 | 101 | 201 | Cindy | Sales | 1500 | paid | 2026-02-02 | 100 |
| 4 | 104 | 203 | David | HR | 700 | cancelled | 2026-02-15 | 0 |
Run result
| id | customer_id | product_id | name | department | amount | status | created_at | discount |
|---|---|---|---|---|---|---|---|---|
| 1 | 101 | 201 | Alice | Sales | 1200 | paid | 2026-01-03 | 0 |
Common issues
How do % and _ differ in LIKE?
% matches any number of characters, while _ matches exactly one character.
Is LIKE case-sensitive?
It depends on the database and collation, so do not assume identical behavior everywhere.
Can a leading % affect index use?
A leading wildcard often prevents effective use of a regular B-tree index and needs care on large tables.
Tags
Was this explanation clear?
Thanks. This feedback will inform the next content review.