5) SQL Commands for Querying Databases Lesson

IN

3 min to complete · By Ryan Desmond

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);
Every film where the release year is in 2004, 2005 or 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;
Every film where the release year is in 2004, 2005 or 2006 but with OR operators instead of IN keyword

Summary: SQL In Statement

  • The SQL IN statement is written inside the WHERE clause to specify multiple values in ()
  • Using SQL IN is equivalent to using multiple OR operators
  • The SQL IN statement 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>)