1
1
Comparative Functions
2
2
=====================
9
The LIKE operator is used to check if field values match a specified pattern, and searches for less-than-exact but similar values.
11
The LIKE operator supports the use of two wildcards. (Wildcards provide more flexibility by allowing any character or group of characters in a string to be acceptable as a match for another string):
13
* Percentage (%): Represents zero or more values.
14
* Underscore (_): Matches exactly one character value.
16
In accordance the SQL standard, LIKE performs matching on a per-character basis. It therefore provides results different from the = comparison operator.
18
The following SELECT statement includes a WHERE clause in order to search for job titles that start with "DIRECTOR", by using the percentage wildcard after the lookup value.
26
WHERE title LIKE 'DIRECTOR%'
27
ORDER BY field, title;
29
14
.. _regex-function:
36
20
.. _regexp-function:
41
Returns values that match a regular expression pattern; they are commonly used for creating complex searches. Here is an example of using a REGEXP (Regular Expression) match:
45
SELECT title, category_name
47
WHERE title REGEXP '^AIRP[LO]'
50
Other REGEXP examples:
54
SELECT 'abcabc' REGEXP 'abc',
57
The search pattern may describe only a part of string. To match entire string, use ^ and $ in the search:
61
SELECT 'abc' REGEXP '^abc$', 'abcabc' REGEXP '^abc$';
63
SELECT 'cde' REGEXP '[a-c]+', 'efg' REGEXP '[a-c]+';
65
SELECT 'abcabc' REGEXP 'ABC', 'abcabc' REGEXP BINARY 'ABC';
67
27
.. _strcmp-function:
72
The purpose of STRCMP is also to compare two strings. This function returns 0 if two strings are the same, -1 if the first argument is smaller than the second according to the current sort order, and 1 otherwise.