LIKE
This page is part of MariaDB's MariaDB Documentation.
The parent of this page is: SQL Operators for MariaDB Enterprise Server
Topics on this page:
Overview
Performs pattern matching.
USAGE
LIKE text
LIKE text ESCAPE character
DETAILS
The LIKE
operator specifies a wildcard text that is matched against a character string. The characters %
and _
are treated as wildcard characters unless they are escaped:
%
(percent) - match a string of any length, including nothing_
(underscore) - match a single character\\
(backslash) - the default escape character
Putting the escape character prior to a wildcard character turns it into a normal character that must exist in the string being matched. The optional ESCAPE character
clause can specify an alternate character to use. Keep in mind that this new escape character does not change the parsing of the string itself, so it cannot be used to try to escape a string's quoting character.
EXAMPLES
CREATE TABLE like_example (
description VARCHAR(20),
example INT
);
INSERT INTO like_example VALUES
('Everything', 42),
('Dalmations', 101),
('Agent', 99),
('50% Off', 13),
('CPU', 64);
SELECT * FROM like_example
WHERE description LIKE '%ing' OR description LIKE '____t';
+-------------+---------+
| description | example |
+-------------+---------+
| Everything | 42 |
| Agent | 99 |
+-------------+---------+
SELECT * FROM like_example
WHERE description LIKE '%#%%' ESCAPE '#';
+-------------+---------+
| description | example |
+-------------+---------+
| 50% Off | 13 |
+-------------+---------+
CHANGE HISTORY
EXTERNAL REFERENCES
Additional information on this topic may be found in the MariaDB Public Knowledge Base.