by Dinesh Thakur Category: SQL Queries

The IN operator allows you to specify multiple values in a WHERE clause. The IN function helps reduce the need to use multiple OR conditions. The SQL IN clause allows you to specify discrete values in your SQL WHERE search criteria. The syntax for using the IN keyword is as follows:

SELECT field(s) FROM table_name WHERE fields IN (v1,v2,v3...);

Inside the query statement itself, the word "IN" replaces the (=) operator after the WHERE declarative and slightly alters the meaning as well. Instead of listing a single value, you may list multiple values and SQL will retrieve the results for each value listed. There are two uses of the IN keyword in SQL first one is the Simple IN Keyword with Where Condition and the second way with NOT IN. To illustrate the usage of the IN command we are going to use the EMP table.

SELECT * FROM emp WHERE deptno IN (10,20,30);

The results provide a list of all records of each of the employee we have listed inside the IN clause (10,20,30). This is a great way to query for all records made by a handful of different deptno as we can see everything these particular employee have ordered thus far.

On the Other Hand SQL NOT IN eliminate a list of specific values from the result set. To illustrate the usage of the Not IN into command we are going to use the EMP table.

SELECT * FROM emp WHERE deptno Not IN (10,20,30);
Related Articles of SQL

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Search Content