How to Use LIKE in SQL
Use LIKE when you need pattern-based text matching instead of exact string equality. This is perfect for search bars, email filtering, prefix matching, suffix checks, and partial admin tools.
What you’ll build or solve
You’ll learn how to use LIKE in SQL with wildcard patterns to match partial text. You’ll also know how to search for starts-with, ends-with, and contains patterns safely.
Learn SQL on Mimo
When this approach works best
This approach is the right choice when text values should match a pattern instead of one exact string.
Common real-world scenarios include:
- Search by customer name
- Email domain filtering
- Product prefix lookups
- URL path matching
- Log message scans
This is a bad idea when you need exact matches only. In that case, = is usually faster and clearer.
Prerequisites
You only need:
- A SQL table with text columns
- Basic
SELECTandWHEREknowledge
Step-by-step instructions
Step 1: Use LIKE with wildcard patterns
Use % to match any number of characters.
SQL
SELECT *
FROM users
WHERE email LIKE '%@gmail.com';
This finds every email ending in @gmail.com.
Use % before and after the text for contains matching.
SQL
SELECT *
FROM products
WHERE name LIKE '%keyboard%';
Use % only at the end for starts-with matching.
SQL
SELECT *
FROM customers
WHERE first_name LIKE 'Alex%';
Use _ when exactly one character can vary.
SQL
SELECT *
FROM codes
WHERE code LIKE 'A_1';
What to look for:
%matches any number of characters_matches exactly one character- Great for partial text search
LIKEworks best on text columns- Exact matches should still use
=
Examples you can copy
Contains search
SQL
SELECT *
FROM articles
WHERE title LIKE '%JavaScript%';
Starts with prefix
SQL
SELECT *
FROM products
WHERE sku LIKE 'PRO-%';
Ends with domain
SQL
SELECT *
FROM users
WHERE email LIKE '%@company.com';
Common mistakes and how to fix them
Mistake 1: Forgetting wildcard symbols
What the reader might do:
SQL
WHERE name LIKE 'Alex'
Why it breaks: this behaves like an exact match.
Corrected approach:
SQL
WHERE name LIKE 'Alex%'
Mistake 2: Using LIKE on numeric columns
What the reader might do:
SQL
WHERE order_id LIKE '10%'
Why it breaks: numeric columns should use numeric filters, not text pattern matching.
Corrected approach:
Use numeric comparisons unless the column is stored as text.
Mistake 3: Leading wildcard on huge datasets
What the reader might do:
SQL
WHERE title LIKE '%error'
Why it breaks: leading wildcards often prevent index usage and slow large queries.
Corrected approach:
Prefer prefix searches when possible.
SQL
WHERE title LIKE 'error%'
Troubleshooting
If no rows match, confirm the wildcard placement.
If the query is slow, avoid leading % on indexed columns.
If exact matches are enough, switch to =.
If case sensitivity behaves differently, check your database collation or use ILIKE where supported.
Quick recap
- Use
LIKEfor pattern matching %matches many characters_matches one character- Great for partial search
- Use
=for exact matches
Join 35M+ people learning for free on Mimo
4.8 out of 5 across 1M+ reviews
Check us out on Apple AppStore, Google Play Store, and Trustpilot