SQL IN Operator – Filter Multiple Values with Examples (2026-27)
The SQL IN operator is used in a WHERE clause to filter rows where a column value matches any value from a specified list. Instead of writing multiple OR conditions like WHERE Department = 'IT' OR Department = 'HR' OR Department = 'Sales', you can write the cleaner, shorter WHERE Department IN ('IT', 'HR', 'Sales'). The IN operator works with numbers, text values, and even subqueries. In this step-by-step guide you will learn the full IN syntax, see five real examples — numbers, text, NOT IN, subquery, and IN with BETWEEN — plus a comparison with OR and the most common mistakes to avoid.
✅ What is the SQL IN Operator?
✅ The SQL IN operator is used in a WHERE clause to filter rows where a column matches any value in a list.
✅ It is a shorthand for multiple OR conditions on the same column.
✅ It works with numbers, text values, and subqueries.
✅ Use NOT IN to exclude all values in the list.
WHERE Department IN ('IT', 'HR', 'Sales') is cleaner, shorter, and gives exactly the same result.
✅ Sample Employees Table used in all examples:-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 1 | ANNI | IT | 10000 | Mumbai |
| 2 | POOJA | IT | 9000 | Pune |
| 3 | RAJ | HR | 5000 | Delhi |
| 4 | SUJAN | HR | 8000 | Pune |
| 5 | MEENA | Sales | 12000 | Mumbai |
| 6 | PRAMOD | Finance | 15000 | Bangalore |
| 7 | NILESH | Sales | 7000 | Delhi |
✅ SQL IN Syntax
SELECT column1, column2, ...
FROM table_name
WHERE column_name IN (value1, value2, value3, ...);
✅ IN:- Keyword — placed after the column name in the WHERE clause.
✅ (value1, value2, ...):- Comma-separated list of values inside parentheses. Text values need single quotes; numbers do not.
✅ NOT IN Syntax:-
SELECT column1, column2, ...
FROM table_name
WHERE column_name NOT IN (value1, value2, value3, ...);
✅ IN with Subquery Syntax:-
SELECT column1, column2, ...
FROM table_name
WHERE column_name IN (SELECT column FROM another_table WHERE condition);
WHERE Department IN ('IT', 'HR') is exactly the same as WHERE Department = 'IT' OR Department = 'HR'. IN is simply cleaner and more scalable.
✅ Example 1 – IN with Text (Department List)
Find all employees who work in the IT or Sales department.
✅ SELECT Query:-
SELECT *
FROM Employees
WHERE Department IN ('IT', 'Sales');
✅ Result:-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 1 | ANNI | IT | 10000 | Mumbai |
| 2 | POOJA | IT | 9000 | Pune |
| 5 | MEENA | Sales | 12000 | Mumbai |
| 7 | NILESH | Sales | 7000 | Delhi |
✅ Example 2 – IN with Numbers (Salary List)
Find employees whose salary is exactly 5000, 9000, or 15000.
✅ SELECT Query:-
SELECT *
FROM Employees
WHERE Salary IN (5000, 9000, 15000);
✅ Result:-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 2 | POOJA | IT | 9000 | Pune |
| 3 | RAJ | HR | 5000 | Delhi |
| 6 | PRAMOD | Finance | 15000 | Bangalore |
✅ Example 3 – NOT IN (Exclude a List of Values)
Find all employees who do NOT work in IT or Finance.
✅ SELECT Query:-
SELECT *
FROM Employees
WHERE Department NOT IN ('IT', 'Finance');
✅ Result:-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 3 | RAJ | HR | 5000 | Delhi |
| 4 | SUJAN | HR | 8000 | Pune |
| 5 | MEENA | Sales | 12000 | Mumbai |
| 7 | NILESH | Sales | 7000 | Delhi |
WHERE column IS NOT NULL to the subquery to be safe.
✅ Example 4 – IN with a Subquery
Find all employees who work in departments that have at least one employee earning more than 10000. (Using a subquery to dynamically build the list.)
✅ SELECT Query:-
SELECT *
FROM Employees
WHERE Department IN (
SELECT Department
FROM Employees
WHERE Salary > 10000
);
✅ Result:-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 1 | ANNI | IT | 10000 | Mumbai |
| 2 | POOJA | IT | 9000 | Pune |
| 5 | MEENA | Sales | 12000 | Mumbai |
| 6 | PRAMOD | Finance | 15000 | Bangalore |
| 7 | NILESH | Sales | 7000 | Delhi |
SELECT Department FROM Employees WHERE Salary > 10000 runs first and returns ('IT', 'Sales', 'Finance') — departments that have at least one high earner. The outer query then uses IN to return ALL employees in those departments — including ANNI, POOJA, and NILESH even though their own salary is not above 10000.
✅ Example 5 – IN Combined with AND and BETWEEN
Find IT or HR employees whose salary is between 5000 and 10000.
✅ SELECT Query:-
SELECT *
FROM Employees
WHERE Department IN ('IT', 'HR')
AND Salary BETWEEN 5000 AND 10000;
✅ Result:-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 1 | ANNI | IT | 10000 | Mumbai |
| 2 | POOJA | IT | 9000 | Pune |
| 3 | RAJ | HR | 5000 | Delhi |
| 4 | SUJAN | HR | 8000 | Pune |
✅ IN vs OR Comparison
Both give identical results when used on the same column. Choose based on readability.
| Feature | IN Operator | OR Operator |
|---|---|---|
| Result | Identical | Identical |
| Readability | Cleaner and shorter | Gets long with many values |
| 3+ values | IN ('IT','HR','Sales') | = 'IT' OR = 'HR' OR = 'Sales' |
| Subquery support | ✅ Yes — IN (SELECT ...) | ❌ No |
| Performance (same column) | Same as OR | Same as IN |
| NOT version | NOT IN (...) | <> 'x' AND <> 'y' |
| Works with NULL in list | ⚠️ NULL causes NOT IN to fail | ⚠️ NULL comparisons also fail |
WHERE City = 'Mumbai' OR Salary > 10000.
✅ Key Points to Remember
✅ IN is shorthand for multiple OR conditions — same result, much cleaner code.
✅ Text values need single quotes — IN ('IT', 'HR'). Numbers do not — IN (5000, 9000).
✅ IN works with subqueries — WHERE ID IN (SELECT ID FROM ...) is one of SQL's most powerful patterns.
✅ NOT IN excludes the list — but avoid NOT IN when the list or subquery might contain NULL values.
✅ Combine with AND / BETWEEN — WHERE Department IN ('IT', 'HR') AND Salary BETWEEN 5000 AND 10000.
✅ Order inside IN does not matter — IN ('IT', 'HR') and IN ('HR', 'IT') return identical results.
✅ For very large lists (100+ values), consider using a temporary table and JOIN for better performance.
✅ Common SQL IN Mistakes to Avoid
Wrong:
WHERE Department IN (IT, HR) — SQL treats IT and HR as column names, causing an error.Correct:
WHERE Department IN ('IT', 'HR') — always use single quotes for text values.
Wrong:
WHERE ID NOT IN (SELECT ManagerID FROM Departments) — if any ManagerID is NULL, this returns 0 rows.Correct:
WHERE ID NOT IN (SELECT ManagerID FROM Departments WHERE ManagerID IS NOT NULL)
Wrong:
WHERE Department IN 'IT', 'HR' — syntax error.Correct:
WHERE Department IN ('IT', 'HR') — the value list must be inside parentheses.
Wrong intent:
WHERE City IN Department — IN compares one column against a fixed list or subquery, not another column directly.Use JOIN or EXISTS instead when comparing two columns from different tables.
WHERE ID IN (1, 2, 3, 4, ... 500) — hundreds of values in an IN list can slow down queries.Better: Insert those IDs into a temporary table and use a JOIN instead.
✅ Frequently Asked Questions (FAQ)
WHERE Department IN ('IT', 'HR', 'Sales') is equivalent to WHERE Department = 'IT' OR Department = 'HR' OR Department = 'Sales'.WHERE Department NOT IN ('IT', 'Finance') returns employees who are not in IT or Finance. Important: If the list or subquery contains any NULL value, NOT IN returns no rows at all. Always add IS NOT NULL to subqueries used with NOT IN.WHERE Department IN (SELECT Department FROM Employees WHERE Salary > 10000). The subquery runs first and produces the list of values, then the outer query filters based on that list. This is one of the most powerful uses of the IN operator.WHERE column IS NOT NULL in the subquery when using NOT IN.