SQL IN Operator - The Coding Shala

Home >> Learn SQL >> SQL IN Operator

SQL IN Operator

The SQL 'IN' Operator allows us to specify multiple values in where clause. The SQL 'IN' Operator is useful when we have multiple 'or' condition. The SQL 'IN' Operator is always used in 'Where' Clause.
SQL IN Operator - The Coding Shala

SQL IN Operator Syntax 

The basic SQL IN operator syntax is as follows - 

 SELECT column_name(s)  
 FROM table_name  
 WHERE column_name IN (value1, value2, ...);  

OR 

SELECT column_name(s)  
 FROM table_name  
 WHERE column_name IN (SELECT STATEMENT);

SQL IN Operator Example 

The following 'emp' table is used for the examples - 

Id     Name     Age     Address     Salary  
 1     Akshay     22     Pune        40000  
 2     Mohit      21     Delhi       42000  
 3     Akash      21     Delhi       45000  
 4     Nikhil     24     Mumbai      50000  
 5     Smith      24     Pune        50000  
 6     Akshay     22     Pune        50000  
 7     Nikhil     24     Mumbai      43000  


The following query will return those records that have 'Address' in Pune or Delhi - 

SQL >> select * from emp  
        where Address IN ("Pune", "Delhi");  
 
Output >>   
 Id     Name     Age     Address     Salary  
 1     Akshay     22     Pune       40000  
 2     Mohit      21     Delhi      42000  
 3     Akash      21     Delhi      45000  
 5     Smith      24     Pune       50000  
 6     Akshay     22     Pune       50000 



Other Posts You May Like
Prev<< SQL Wildcard Operator                                                                    NEXT >>SQL BETWEEN Operator
Please leave a comment below if you like this post or found some error, it will help me to improve my content.

Comments

Popular Posts from this Blog

Shell Script to find sum, product and average of given numbers - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala

Add two numbers in Scala - The Coding Shala

LeetCode - Number of Good Pairs Solution - The Coding Shala

Richest Customer Wealth LeetCode Solution - The Coding Shala