SQL - SPLessons

SQL IN Condition

Chapter 24

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

SQL IN Condition

SQL IN Condition

shape Description

SQL IN Condition is used when trying to match a value from a discrete value set. It will prevent to use multiple or condition in Where Clause statement.

shape Conceptual

shape Syntax

Select <column_name> from <table_name> where column_name IN (value1,value2,…);

Table name => The accurate table in the database.

column name => The operations that can be performed in the column.

shape Examples

When tried to find the customer details whose branch is in Downtown or in Brighton, then write like below:

sql>SELECT cust_id, cust_name FROM cust_det WHERE branch in ('Downtown','Brighton');


shape Description

Here IN condition prevents from multiple OR executions. It is very useful in sub queries when it is not known if the result of the sub query will be a single value or multiple like below.

shape Examples

The SQL IN condition is used in subquery.

sql>SELECT account_number
FROM accounts
WHERE cust_id
IN (SELECT cust_id
FROM cust_det
WHERE branch ='Downtown' OR branch ='Brighton'); 

In the above example the sub query will return multiple values and the outer query will search the customer account numbers who have a account in branch ‘Downtown’ or ‘Brighton’.


shape Key Points

SQL IN Condition – Is used when we are trying to match a value from a discrete value set.