• Teach Your Self With
             w3htmlschool.com

MySQL IN Operator

The MYSQL IN Operator check if a stated value matches any one of a list.Is very good alternate of OR conditions in a SELECT, INSERT, UPDATE, or DELETE statement.

Syntax


SELECT DISTINCT
columns
FROM
table_name
WHERE COLUMN in(list of value...);
Table

+-------------+----------+
| Field | Type |
+-------------+----------+
| ID | int(11) |
| Name | char(35) |
| CountryCode | char(3) |
| District | char(20) |
| Population | int(11) |
+-------------+----------+
Example
select * from city where name in('Ede','Annaba','Herat');
Output
mysql> select * from city where name in('Ede','Annaba','Herat');
+----+--------+-------------+------------+------------+
| ID | Name | CountryCode | District | Population |
+----+--------+-------------+------------+------------+
| 3 | Herat | AFG | Herat | 186800 |
| 29 | Ede | NLD | Gelderland | 101574 |
| 38 | Annaba | DZA | Annaba | 222518 |
+----+--------+-------------+------------+------------+
3 rows in set (0.00 sec)