Select In in SQL
? SELECT ... IN in SQL
The IN operator is used in the WHERE clause to filter rows where a column's value matches any value in a specified list or subquery.
? Syntax:
SELECT column1, column2, ...FROM table_nameWHERE column_name IN (value1, value2, value3, ...);Or with a subquery:
SELECT column1, column2, ...FROM table_nameWHERE column_name IN (SELECT other_column FROM other_table WHERE condition);? Examples:
Select employees in specific departments:
SELECT name, departmentFROM employeesWHERE department IN ('Sales', 'Marketing', 'HR');Select products with IDs from another table:
SELECT product_nameFROM productsWHERE product_id IN (SELECT product_id FROM orders WHERE order_date > '2025-01-01');? Notes:
INis a shorthand for multipleORconditions.WHERE department = 'Sales' OR department = 'Marketing' OR department = 'HR'Can improve query readability and performance.
When the list inside
INis empty, the condition returns no rows.Use with caution with NULL values, as
NULL IN (… )returnsUNKNOWN(no match).
Want to see how IN compares with EXISTS or how to use it with subqueries?