Quantcast
Viewing all articles
Browse latest Browse all 1801

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)

id f_name l_name position age salary email
1 Piolo Pascual Programmer 38 25000 piolopascual@yahoo.com
2 Sam Milby System Analyst 34 20000 sammilby@yahoo.com
3 John Lloyd Cruz Network Administrator 33 20000 johnllyodcruz@yahoo.com
4 Rolan Algara Encoder 19 55000 cuteness_tyron@yahoo.com
5 Jericho Rosales Encoder 25 55000 jerichorosales@yahoo.com
6 John Prats Programmer 24 15000 johnprats@yahoo.com

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)
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 1801

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>