MySQL Tutorial – Using the IN function

The IN function can be used to replace the OR condition. It is also used to specify multiple value together with the WHERE clause.

The syntax of IN function:

SELECT column_name(s)
FROM table_name
Where column_name IN (value1,value2,etc…);

Let’s see some example:

database table: (employee_record)

[TABLE=3]

We want to select the firstname and lastname of the employees with the position of  “Programmer” or “Encoder”. Issue the following command:

SELECT f_name, l_name
FROM employee_record
Where position IN (“Programmer”,”Encoder”);

Result:

+---------+---------+
| f_name  | l_name  |
+---------+---------+
| Piolo   | Pascual |
| Rolan   | Algara  |
| Jericho | Rosales |
| John    | Prats   |
+---------+---------+
4 rows in set (0.00 sec)

The IN function can be used to replace the OR condition. It is also used to specify multiple value together with the WHERE clause.

The syntax of IN function:

SELECT column_name(s)
FROM table_name
Where column_name IN (value1,value2,etc…);

Let’s see some example:

database table: (employee_record)

[TABLE=6]

We want to select the firstname and lastname of the employees with the position of  “Programmer” or “Encoder”. Issue the following command:

SELECT f_name, l_name
FROM employee_record
Where position IN (“Programmer”,”Encoder”);

Result:

+---------+---------+
| f_name  | l_name  |
+---------+---------+
| Piolo   | Pascual |
| Rolan   | Algara  |
| Jericho | Rosales |
| John    | Prats   |
+---------+---------+
4 rows in set (0.00 sec)

Comments

comments

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.