1.3

LIKE and REGEXP Operators

LIKE and REGEXP Operators

Table 2. LIKE Keyword

LIKE Symbol

Description

%

Match any string of characters to the left of the symbol

_

Match a single character

Code Example:

USE world;
SELECT name
FROM country
WHERE name LIKE ‘A%’

Results:

LIKE.png

Table 3. REXEXP Keyword

REGEXP Characters

Description

^

Match the pattern to the beginning of the value being tested.

$

Match the pattern to the end of the value being tested.

.

Matches any single character.

[charlist]

Matches any single character listed within the brackets.

[char1 – char2]

Matches any single character within the given range.

|

Separates two string patterns and matches either one

Code Example:

USE world;
SELECT name
FROM country
WHERE name REGEXP 'g[o,u]';

Results:

REGEXP.png

CC BY-NC-ND International 4.0

CC BY-NC-ND International 4.0: This work is released under a CC BY-NC-ND International 4.0 license, which means that you are free to do with it as you please as long as you (1) properly attribute it, (2) do not use it for commercial gain, and (3) do not create derivative works.