Database Reference
In-Depth Information
Note
Predicates When is an operator not an operator? When it is a
predicate
. Technically,
LIKE
is a predicate, not an operator. The end result is the same; just be aware of this
term in case you run across it in the MariaDB documentation.
The most frequently used wildcard is the percent sign (
%
). Within a search
string,
%
means
match any number of occurrences of any character
. For example,
to find all products that start with the word
jet
, you can issue the following
SELECT
statement:
▼
Input
SELECT prod_id, prod_name
FROM products
WHERE prod_name LIKE 'jet%';
▼
Output
+---------+--------------+
| prod_id | prod_name |
+---------+--------------+
| JP1000 | JetPack 1000 |
| JP2000 | JetPack 2000 |
+---------+--------------+
▼
Analysis
This example uses a search pattern of
'jet%'
. When this clause is evaluated,
any value that starts with
jet
is retrieved. The
%
tells MariaDB to accept any
characters after the word
jet
, regardless of how many characters there are.
Note
Case-Sensitivity Depending on how the column is defined in MariaDB, searches might
be case-sensitive, in which case
'jet%'
would not match
JetPack 1000
.
Wildcards can be used anywhere within the search pattern, and multiple wild-
cards can be used as well. The following example uses two wildcards, one at
either end of the pattern:
▼
Input
SELECT prod_id, prod_name
FROM products
WHERE prod_name LIKE '%anvil%';