Share
MySQL IN Operator
The IN operator allows you to specify multiple values in a WHERE clause.
MySQL IN Syntax
SELECT column_name(s) FROM table_name WHERE column_name IN (value1,value2,...)
MySQL IN Operator Example
The "Persons" table:
| ID | First Name | Last Name | Address |
| 1 | Putu | Sanjaya | Denpasar |
| 2 | Made | Sanjaya | Sanur |
| 3 | Haru | Sanjaya | Gianyar |
Now we want to select the persons with a last name equal to "Putu" or "Haru" from the table above. We use the following SELECT statement:
SELECT * FROM Persons WHERE FirstName IN ('Putu','Haru')
The result-set will look like this:
| ID | First Name | Last Name | Address |
| 1 | Putu | Sanjaya | Denpasar |
| 3 | Haru | Sanjaya | Gianyar |
More Tutorial
- MYSQL - MySQL IN Operator