Press "Enter" to skip to content

mysqllikeoperator

MySQL LIKE Operator

The mysql LIKE operator is used for select data based on patterns or in other words comparison based on wildcards . Using the LIKE operator in the right way is important to increase the query performance in a SELECT, INSERT, UPDATE, or DELETE statement.

SYNTAX


SELECT * FROM table_name
WHERE COLUMN NAME
LIKE (pattern)

Table structure Used for Example explanation

+————-+———-+
| Field | Type |
+————-+———-+
| ID | int(11) |
| Name | char(35) |
| CountryCode | char(3) |
| District | char(20) |
| Population | int(11) |
+————-+———-+

Example for MySQL LIKE Operator

select name from city where name like(‘A%’);

Output of Above Example

+——————-+
| name |
+——————-+
| Amsterdam |
| Apeldoorn |
| Almere |
| Arnhem |
| ´s-Hertogenbosch |
| Amersfoort |
| Alkmaar |
| Alger |
| Annaba |
+——————-+
9 rows in set (0.07 sec)