IN Operator - SQL


Overview


The IN Operator in SQL is used to filter the result set to include only the rows where the value of a specified column matches any value in a given list. It is a shorthand for multiple OR conditions.

Syntax:

SELECT column
FROM table_name
WHERE column1 IN (value1, value2, ..., valueN)

column1 IN (value1, value2, ..., valueN) checks if the value in column1 matches any of the values in the list (value1, value2, ..., valueN).

Sample Data:

department_id first_name
3 Frank
2 Jane
3 Ashley
NULL Glenn
2 Kelly
1 Richard
1 George
5 Kyle
2 James
1 Gustavo

Example


In this example, we are returning the department_id and the first_name column. We then use the IN operator to filter the results to only include rows where the department_id column is either 1, 2, or 3.

Example:

SELECT department_id, first_name
FROM company.employees
WHERE department_id IN (1, 2, 3)