IN Operator in SQL Query

Use of IN Operator in SQL Query

IN Operator is worked as equal to operator but it able to match more rows than 1 rows as in Equal operator.
We are able to match multiple data value with column value to get result in single SQL Statement.
Note:
If we are not able to use IN operation then as alternative we use UNION ALL and EQUAL to match one by one value.

SYNTAX:

SELECT * FROM table_name WHERE columnname IN (value1,value2,...);

Example 1:
Find data for multiple values for specific column, it will return result all rows which having country value INDIA and UK.

SELECT * FROM employees WHERE Country IN ('INDIA','UK');

Example 2:
Main use of IN oparator is use of sub-queries. It will used one query output as another query input with IN Operator. In this example you find the department id from department name and find all employees detail of that department number.

select * from employee where deptno in ( select department_no from departments where department_name = 'SALES');

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.