The LIKE operator is used to check if field values match a specified pattern, and searches for less-than-exact but similar values.
8
8
9
An initial example is: ::
9
An initial example is:
10
11
.. code-block:: mysql
10
12
11
13
SELECT 'ä' LIKE 'ae' COLLATE latin1_german2_ci;
12
14
13
15
Returns 0
14
16
15
Whereas ::
17
Whereas:
18
19
.. code-block:: mysql
16
20
17
21
SELECT 'ä' = 'ae' COLLATE latin1_german2_ci;
18
22
27
31
28
32
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.
29
33
30
For example: ::
34
For example:
35
36
.. code-block:: mysql
31
37
32
38
SELECT title, field
33
39
FROM job_detail
38
44
REGEXP
39
45
------
40
46
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: ::
47
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:
48
49
.. code-block:: mysql
42
50
43
51
SELECT title, category_name
44
52
FROM film_detail
45
53
WHERE title REGEXP '^AIRP[LO]'
46
54
ORDER BY title;
47
55
48
Other REGEXP examples: :;
56
Other REGEXP examples:
57
58
.. code-block:: mysql
49
59
50
60
SELECT 'abcabc' REGEXP 'abc',
51
61
'abcabc' REGEXP 'cb';
52
62
53
The search pattern may describe only a part of string. To match entire string, use ^ and $ in the search: ::
63
The search pattern may describe only a part of string. To match entire string, use ^ and $ in the search: