MariaDB LIKE
To filter the results, the MariaDB LIKE condition is used with a combination of WHERE Clause in SELECT, INSERT, UPDATE and DELETE statements to perform pattern matching.
Syntax:
WHERE expressions LIKE pattern [ ESCAPE 'escape_character' ]
Parameters:
expressions: It is used to specify a column or a field.
pattern: It is used to specify the character expression for pattern matching.
escape_character: It is an optional parameter which is used to test for literal instances of a wildcard character such as
Example: Using wildcard: Percent Students table:
ID NAME AGE 1 Joy 5 2 Smiley 13 3 Happy 11 4 Tom 15 5 Jerry 10 6 Davison 6 7 David 8
Query:
SELECT age FROM students WHERE name LIKE 'Dav%'; |
Output:
AGE 6 8
Example: Using wildcard: Underscore(_).
Students table:
ID NAME AGE 1 Joy 5 2 Smiley 13 3 Happy 11 4 Tom 15 5 Jerry 10 6 Davison 6 7 David 8
Query:
SELECT age FROM students WHERE name LIKE 'Dav_son'; |
Output:
AGE 6
Example: Using NOT.
Students table:
ID NAME AGE 1 Joy 5 2 Smiley 13 3 Happy 11 4 Tom 15 5 Jerry 10 6 Davison 6 7 David 8
Query:
SELECT age FROM students WHERE name NOT LIKE 'Dav%'; |
Output:
AGE 5 13 11 15 10