SQL LIKE Function
Quick summary: The SQL LIKE operator searches for a specified pattern in a column.
SQL LIKE Syntax
WHERE column_name LIKE pattern
SQL
SQL LIKE Basic examples
SELECT * FROM users WHERE email LIKE '%@gmail.com';
SQL
Output:
Gmail users
Matches values ending with a pattern.
SQL LIKE Real-world usage
SELECT * FROM products WHERE name LIKE '%phone%';
SQL
Output:
Products containing "phone"
Implements basic text search.
SQL LIKE Edge cases
SELECT * FROM users WHERE name LIKE '_ohn';
SQL
Output:
Names like John
_ matches a single character.
SQL LIKE Common mistakes
Leading wildcard prevents index usage
LIKE with % at the start disables indexes.
Incorrect
LIKE '%test'
Correct
LIKE 'test%'
Avoid leading wildcards for performance.
SQL LIKE Frequently Asked Questions
What does LIKE do in SQL?
Performs pattern matching in strings.
Use case of LIKE?
Search by pattern.
Wildcard characters?
% and _.
Common mistake?
Using leading wildcard slows queries.
Case sensitivity?
Depends on collation.
Performance impact?
Slow with leading %.
Alternative?
Full-text search.
Supports NOT LIKE?
Yes.
Used with WHERE?
Yes.
Supports indexes?
Only without leading %.
Best practice?
Avoid leading wildcard.
Used in search features?
Yes.