LIKE

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

Release Series

History

10.6 Enterprise

  • Present starting in MariaDB Enterprise Server 10.6.4-1.

10.6 Community

  • Present starting in MariaDB Community Server 10.6.0.

10.5 Enterprise

  • Present starting in MariaDB Enterprise Server 10.5.3-1.

10.5 Community

  • Present starting in MariaDB Community Server 10.5.0.

10.4 Enterprise

  • Present starting in MariaDB Enterprise Server 10.4.6-1.

10.4 Community

  • Present starting in MariaDB Community Server 10.4.0.

10.3 Enterprise

  • Present starting in MariaDB Enterprise Server 10.3.16-1.

10.3 Community

  • Present starting in MariaDB Community Server 10.3.0.

10.2 Enterprise

  • Present starting in MariaDB Enterprise Server 10.2.25-1.

10.2 Community

  • Present starting in MariaDB Community Server 10.2.0.

EXTERNAL REFERENCES