The SQL IN statement allows you to specify multiple values in the WHERE clause.
How Does the SQL In Statement Work?
The SQL IN statement is functionally equivalent to having multiple OR boolean conditions, where any of the conditions can be TRUE. To use SQL IN, place the keyword inside the WHERE clause followed by a list of values in ().
SQL In Example
In the following SQL IN example, you'd select all films released in 2004, 2005, or 2006 from the MySQL Sakila demo database.
SELECT * FROM film
WHERE release_year IN (2004, 2005, 2006);
The SQL IN example above is functionally equivalent to the query below:
SELECT * FROM film
WHERE release_year = 2004
OR release_year = 2005
OR release_year = 2006;
Summary: SQL In Statement
- The SQL
INstatement is written inside theWHEREclause to specify multiple values in () - Using SQL
INis equivalent to using multipleORoperators - The SQL
INstatement can contain as many values as you'd like
SQL In Syntax
Here's how you write the SQL IN statement, where you can substitute the variables in < > with your values.
SELECT <YOUR_COLUMNS>
FROM <YOUR_TABLE>
WHERE <YOUR_COLUMN> IN (<YOUR_VALUE_1>, <YOUR_VALUE_2>)