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

Java Program to Convert Binary to Decimal - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala

N-th Tribonacci Number Solution - The Coding Shala

LeetCode - Shuffle the Array Solution - The Coding Shala

Introduction to Kotlin Programming Language for Backend Development - The Coding Shala