LIKE is a SQL operator for pattern matching. Use it in a WHERE clause to filter rows where a string column matches a specified pattern.
Note: MaxCompute SQL supports only the UTF-8 character set. If your data uses a different encoding, query results may be incorrect.
Wildcard characters
LIKE supports two wildcard characters:
| Wildcard | Matches |
|---|---|
% |
Any sequence of zero or more characters |
_ |
Exactly one character |
To match a literal % or _, escape it with a backslash:
| To match | Use |
|---|---|
% |
\\% |
_ |
\\_ |
Examples
Filter rows using `%`
SELECT * FROM orders WHERE product_name LIKE 'Max%';
Returns all rows where product_name starts with Max. The % wildcard matches any sequence of characters after Max.
`%` matches any sequence of characters — result: `true`
select 'abcd' like 'ab%';
'abcd' starts with ab, and % matches the remaining characters cd.
`_` matches exactly one character — result: `false`
select 'abcd' like 'ab_';
'abcd' has four characters, but 'ab_' requires exactly three. The pattern does not match.
Escaped `\_` matches a literal underscore — result: `true`
select 'ab_cde' like 'ab\\_c%';
\\_ matches the literal underscore in 'ab_cde', and % matches the remaining characters de.
What's next
For regular expression-based pattern matching, see RLIKE.