Press "Enter" to skip to content

mysqlinoperator

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

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 IN Operator

select * from city where name in(‘Ede’,’Annaba’,’Herat’);

Output of Above Example

+—-+——–+————-+————+————+
| 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)