QA
Beginner LevelSQL & MySQL

How do LIKE wildcards (% and _) execute pattern matching in SQL?

❓ Interview Prompt: Explain `LIKE` operator, percent wildcard (`%`), underscore wildcard (`_`), case sensitivity, and index performance pitfalls.

The 'LIKE' operator filters string columns based on pattern matching wildcards:

Wildcard Symbols:

•
'%' (Percent): Matches zero, one, or multiple characters (e.g. ''A%'' matches ''Alice'', ''Bob%'' matches ''Bobby'').
•
'_' (Underscore): Matches exactly one single character (e.g. ''c_t'' matches ''cat'' or ''cut'').
•
⚠️ Index Caveat: Prefix wildcards ('LIKE '%term'') CANNOT use standard B-Tree indexes, triggering full table scans!

Code Implementation Example

sql
-- Efficient leading-text search (uses B-Tree index)
SELECT id, email
FROM users
WHERE email LIKE 'admin@%';
💡Pattern matching emails with leading text using LIKE.
🎯 Interview Key Takeaway

Avoid leading wildcard searches (LIKE '%term') on large tables as they bypass B-Tree indexes and cause full table scans.

#SQL#LIKE#Wildcards#Pattern Matching#Beginner
Back to all SQL & MySQL Questions→

More SQL & MySQL Interview Questions

Beginner LevelSQL & MySQL

How do B-Tree Indexes work in SQL/MySQL and how do you optimize slow queries using EXPLAIN?

Beginner LevelSQL & MySQL

How do SELECT, WHERE, ORDER BY, and LIMIT clauses filter relational datasets?

Beginner LevelSQL & MySQL

What are INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN?