SQL LIKE operator

Here is a clean and practical guide to the SQL LIKE operator, with patterns, examples, and best practices for different SQL engines.
What the SQL LIKE operator Does
LIKE is used in SQL to match text patterns using wildcards.
It is commonly used in WHERE clauses to perform partial string searches.
Wildcards Used with LIKE
| Wildcard | Meaning |
|---|---|
% | Matches zero or more characters |
_ | Matches exactly one character |
Basic Examples
1. Starts with
2. Ends with
3. Contains
4. Single-character match
Case Sensitivity Notes
MySQL:
LIKEis case-insensitive in most collationsPostgreSQL:
LIKEis case-sensitiveUse
ILIKEfor case-insensitive matching
Escape Special Characters
To search for % or _, use ESCAPE:
LIKE with NOT
Performance Tips
- Use indexed columns when possible
- Avoid leading
%(e.g.,%text%) if you want index usage - Consider FULL TEXT SEARCH for complex matching
- Use ILIKE or lower() for case-insensitive search in PostgreSQL
