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](https://kingfishertechtips.in/wp-content/uploads/2024/05/image-63.png)
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](https://kingfishertechtips.in/wp-content/uploads/2024/05/image-64.png)
Watch!
Next Post >> #2.6) Between Operators
<<Previous Post #2.4) AND, OR, NOT Operator