Oracle – IN Condition

IN

admin Condition, Oracle

Hey people,
In this Oracle tutorial, we will learn how to use IN condition in SQL. IN condition is used in SQL with every database.

IN condition helps to check multiple values in a column or we can say, it reduces the use of OR condition in a SQL statement.
As it is a condition and helps to limit the rows to be returned by SQL statement, it is used just after the WHERE clause.

Syntax-1: Using the expressions list

WHERE column_name IN (value1, value2, … value_n);

Syntax-2: Using the subquery/select query

WHERE column_name IN (subquery/select query);

Parameters or Arguments:

column_name

This is the column of the table in which we need to look the values.

value1, value2, … value_n

These are values that we need to check in the specified column. These values should be aligned between single quotes and comma separated as these are char values.

subquery/select query

This is a SELECT statement whose result set will be tested against the values in the specified column.

Below explample is showing how we can select a few rows from Employees table (HR schema) using equality operator.

Example-1:

Example-2 will show how easy it is when we use IN condition.

Example-2:

Both the SQL statements will give the same output but IN condition helps to shorten the code.

Example-3 will show you how we can we a select statement in IN condition.

Example-3:

Eventually, 3rd example shows both methods of using IN condition in SQL statement.

Note:
When we supply char values to the IN condition, we can only supply 1000 values.

If you have any questions/suggestions, please comment below or write me an email.
If you like this blog, do share with your friends and colleagues on your social media.
For more updates join my facebook group and do like my facebook page.

Thank you,
Kapil Kumar

Sharing is caring!

You May Also Like..

NULLIF

Oracle SQL_Null Related functions-3_NULLIF

Hi Aliens, Today, we will talk about another Null Related Function, NULLIF. You can read my notes on NVL, NVL2 […]

WHERE

SQL – WHERE clause

Hi DBgeek Army, Welcome back to the world of Oracle! Where clause helps to select desired rows or helps to […]

comments

Comment in SQL and PL-SQL

Hi DBgeek Army, Welcome back to the world of Oracle! Comments are very important aspects of our code. No matter […]

Leave a Reply

Your email address will not be published. Required fields are marked *