Database Reference
In-Depth Information
8
In this chapter, you learn what wildcards are, how they are used, and how to
perform wildcard searches using the
LIKE
operator for sophisticated filtering of
retrieved data.
All the previous operators we studied filter against known values. Be it match-
ing one or more values, testing for greater-than or less-than known values, or
checking a range of values, the common denominator is that the values used in
the filtering are known. But filtering data that way does not always work. For
example, how could you search for all products that contained the text
anvil
within the product name? That cannot be done with simple comparison opera-
tors; that's a job for wildcard searching. Using wildcards, you can create search
patterns that can be compared against your data. In this example, if you want
to find all products that contain the word
anvil
, you could construct a wildcard
search pattern enabling you to find that
anvil
text anywhere within a prod-
uct name.
New Term
Wildcards Special characters used to match parts of a value.
New Term
Search pattern A search condition made up of literal text, wildcard characters, or any
combination of the two.
The wildcards themselves are actually characters that have special meanings
within SQL
WHERE
clauses, and SQL supports several wildcard types.
To use wildcards in search clauses, the
LIKE
operator must be used.
LIKE
instructs MariaDB that the following search pattern is to be compared using a
wildcard match rather than a straight equality match.