Jump to: navigation, search

Mysql LIKE

From w3cyberlearnings

Contents

MySQL LIKE Function

This function returns 1 when it is found, else it returns 0.

Syntax LIKE

  • expre: String
  • Str: String to look for.
expre LIKE Str;

Example 1

mysql> SELECT 'go to school' LIKE 'go to school';
+------------------------------------+
| 'go to school' LIKE 'go to school' |
+------------------------------------+
|                                  1 |
+------------------------------------+
1 row in set (0.00 sec)

Example 2

mysql> SELECT 'go to school' LIKE 'go to';
+-----------------------------+
| 'go to school' LIKE 'go to' |
+-----------------------------+
|                           0 |
+-----------------------------+
1 row in set (0.00 sec)

Example 3

mysql> SELECT 'go to school' LIKE 'go to%';
+------------------------------+
| 'go to school' LIKE 'go to%' |
+------------------------------+
|                            1 |
+------------------------------+
1 row in set (0.00 sec)

Example 4

mysql> SELECT 'go to school' LIKE 'to%';
+---------------------------+
| 'go to school' LIKE 'to%' |
+---------------------------+
|                         0 |
+---------------------------+
1 row in set (0.00 sec)

Example 5

mysql> SELECT 'go to school' LIKE '%to%';
+----------------------------+
| 'go to school' LIKE '%to%' |
+----------------------------+
|                          1 |
+----------------------------+
1 row in set (0.00 sec)

Example 6

mysql> SELECT 'PaulC' LIKE 'Paul_';
+----------------------+
| 'PaulC' LIKE 'Paul_' |
+----------------------+
|                    1 |
+----------------------+
1 row in set (0.00 sec)


Example 7

mysql> SELECT 'CaulC' LIKE '_aul_';
+----------------------+
| 'CaulC' LIKE '_aul_' |
+----------------------+
|                    1 |
+----------------------+
1 row in set (0.00 sec)

Example 8

  • LIKE BINARY: make the search case sensitive.
mysql> SELECT 'PaulC' LIKE BINARY 'Paulc';
+-----------------------------+
| 'PaulC' LIKE BINARY 'Paulc' |
+-----------------------------+
|                           0 |
+-----------------------------+
1 row in set (0.01 sec)

Related Links


Navigation
Web
SQL
MISC
References