Home » MariaDB Like

MariaDB LIKE Clause

In MariaDB, LIKE clause is used with SELECT statement to retrieve data when an operation needs an exact match. It can be used with SELECT, INSERT, UPDATE and DELETE statement.

It is used for pattern matching and return a true or false. The patterns used for comparison accept the following wildcard characters:

“%” wildcard character: It matches numbers of characters (0 or more).

“_” wildcard charcter: It matches a single character. It matches characters within its set.

Syntax:

Example:

Using % wildcard (percent sign wildcard)

We have a table “Employees”, having the following data.

Mariadb like clause 1

Let’s use % wildcard with LIKE condition to find all of the names who begins with “L”.

Example1:

Output:

Mariadb like clause 2

You can also use the % wildcard multiple times within the same string.

Example2:

Output:

Mariadb like clause 3

It will return all names which contains “L” within.


Using _ wildcard (underscore wildcard)

Let’s use _ wildcard with LIKE condition. The underscore wildcard checks only one character. Let’s fetch name of the employee which is like “Ra_ul”.

Output:

Mariadb like clause 4


LIKE Clause with NOT operator

In MariaDB, you can use NOT operator with LIKE clause. Let’s use the % wilcard with the NOT Operator. Here we find out employees whose name does not start with ‘A’.

Output:

Mariadb like clause 5

Next TopicMariaDB Order By

You may also like