The underscore (_) wildcard commonly represents exactly one character in a LIKE pattern.
It is useful when the position and length of a text pattern are known but one or more characters may vary.
Find product codes where the second character can be any character.
SELECT
ProductCode
FROM Products
WHERE ProductCode LIKE 'A_25';
Underscore patterns can be useful for code validation, formatted identifiers, and structured text searches.
- _ commonly matches exactly one character.
- Multiple underscores can match multiple individual characters.
- It can be combined with %.
- It is useful for structured text patterns.
- Wildcard behavior can vary slightly by database.
What does _ mean in LIKE?
The underscore wildcard commonly matches exactly one character.
Can _ and % be used together?
Yes. SQL LIKE patterns can combine different wildcard characters.