IN condition is an alternative to multiple OR conditions in SELECT, INSERT, UPDATE, or DELETE statement. The IN operator allows multiple values to be tested against the expression and thus reduces the use of multiple OR conditions with each test value.
expression IN (value1, value2, .... value_n);
1. expression : value/attribute to be tested.
2. value1, value2, .. value_n : The values to be tested against expression.
Creating Table GEEKS_6
Inserting values into Table GEEKS_6:
Selecting multiple values using ‘OR’. Multiple OR’s have to be used for checking the expression.
The same query can be answered using ‘IN’ which reduces the number of times conditions have to be written and all test values are present at a single place.
Example 2 : Using ‘IN’ with two tables>
Creating Table GEEKS_7:
Inserting values into Table GEEKS_7:
Query: Find the common elements from two tables using ‘IN’
The inner query will be executed first and all the values in the ‘name’ column of Table Geeks_7 will be selected. Then the outer query will start executing and it will use the inner query values to filter out matching values.
- Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
- Delete statement in MS SQL Server
- SQL Server Mathematical functions (SQRT, PI, SQUARE, ROUND, CEILING & FLOOR)
- SQL Server Identity
- SQL SERVER | Conditional Statements
- SQL Server | STUFF() Function
- SQL Server | SERVERPROPERTY()
- Mean and Mode in SQL Server
- Allow only alphabets in column in SQL Server
- Reverse Statement Word by Word in SQL server
- Copy tables between databases in SQL Server using Import-and-Export Wizard
- Difference between MySQL and MS SQL Server
- Comparisons between Oracle vs SQL Server
- Introduction of MS SQL Server
- Select statement in MS SQL Server
- Order by in MS SQL Server
- Distinct clause in MS SQL Server
- Where clause in MS SQL Server
- Difference between Couchbase and MS SQL Server
- Create, Alter and Drop schema in MS SQL Server
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.