LIKE, Wildcards and Escaping
Pattern matching, percent vs underscore, and escaping literal wildcard characters.
Pattern Matching Under Interview Scrutiny
LIKE looks simple but hides three classic interview gotchas: confusing % with _, forgetting that a literal percent or underscore in the data needs escaping, and the case-sensitivity surprise that differs by database.
This lesson drills the two wildcards, the ESCAPE clause, and the cross-dialect rules an interviewer will probe to separate juniors from people who have shipped real search features.
The Two Wildcards
LIKE has exactly two wildcard characters:
%matches zero or more characters_matches exactly one character
So 'a%' matches anything starting with a, while 'a_' matches a two-character string starting with a. Mixing these up is the number one LIKE mistake.
SELECT *
FROM customers
WHERE name LIKE 'A%';
-- every name beginning with AAll lessons in this course
- AND/OR Precedence and Parenthesization
- BETWEEN, IN, and Inclusive Boundaries
- LIKE, Wildcards and Escaping
- Filtering on Calculated Values