SQL IN
Summary: In this tutorial, you will learn how to use SQL IN operator along with SQL WHERE clause to retrieve data in a set of values.
SQL IN operator allows you to determine if a value is contained in a set of values. The syntax of using SQL IN operator is as follows:
SELECT column_list
FROM table_name
WHERE column IN (value1, value2, value3…)
It is important to note that the set of values must be comma-delimited and enclosed within parentheses.
For example, to find all products which have unit price are $18, $19 and $20, you can perform the following query:
SELECT productName, unitPrice
FROM products
WHERE unitPrice IN (18, 19, 20)

SQL IN helps you to write multiple OR operator in the WHERE clause . You can use OR operator to rewrite the above query as follows:
SELECT productName, unitPrice
FROM products
WHERE unitPrice = 18 OR unitPrice = 19 OR unitPrice = 20
When values are extended, the query that uses OR operators will be more complicated and difficult to read. So whenever you write a query that have multiple OR operators, remember SQL IN operator to make your query easier to read and maintain.
The SQL IN operator can combine with NOT operator. To find all records which has a column value are not in a set you can use NOT IN. For instance, you can find all products which have unit price not 18 and not 19 and not 20 by performing the following query:
SELECT productName, unitPrice
FROM products
WHERE unitPrice NOT IN (18, 19, 20)
The following picture illstrate the the excerpt of the result:

Beside these above usages, SQL IN operator is also used in subquery which you will learn later in SQL subquery tutorial.
In this tutorial, you’ve learned how to use SQL IN operator to find data which have value in a set. You've also learned how to use SQL IN combine with NOT operator to query data that not in a set of values.
SQL IN operator, you learn how to use SQL IN to find value in a set of values. SQL IN tutorial with examples. SQL IN to combine with SQL NOT operator.SQL IN tutorial with clear explaination.
Related Tutorials