SQL IN Operator | Querying Data from Single Table

SQL IN Operator: The IN operator lets you filter rows where a column has any value from a given list. You can also provide a subquery inside the IN operator.

SQL IN Operator

1. The IN operator is used when we want multiple values to return.

2. If we see the first query, we have multiple arguments to get values for different states.

3. Now, instead of using multiple time’s state. We can directly specify IN and provide the values which you want from state table (Refer 2nd query).

4. We can also use NOT operator before IN operator to get values apart from the specified values.

The below is the explanation for using OR & AND operator, but you can see in the below 2nd query on how to use the IN and achieve the same thing!

SELECT *
FROM customers
WHERE state = '2' OR state ='8' OR state ='10';
SQL IN Operator

The below is the usage of SQL IN Operator, and it is pretty easy to implement. For more about this check this document!

SELECT *
FROM customers
WHERE customer_id IN (2,8,10);
SQL IN Operator

Watch!

Next Post >> #2.6) Between Operators

<<Previous Post #2.4) AND, OR, NOT Operator

Vickey Rajpoot
Vickey Rajpoot

Hello there! I'm dedicated Microsoft Data & AI Engineer at LTIMindtree, where I thrive technology into actionable insights. Dive into my world by visiting my YouTube channel & Webiste, "Kingfisher Tech Tips".

Articles: 114

Leave a Reply

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