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 much cleaner WHERE Department IN ('IT', 'HR', 'Sales'). The IN operator works with numbers, text, dates, and even subqueries — making it one of the most versatile filtering tools in SQL. In this step-by-step guide you will learn the full IN syntax, see five real examples, understand NOT IN, use IN with a subquery, and learn the most common mistakes to avoid.
✅ What is the SQL IN Operator?
✅ The SQL IN operator filters rows where a column value matches any value from a given list.
✅ It is a clean shorthand for multiple OR conditions on the same column.
✅ Works with numbers, text, dates, and subqueries.
IN ('IT', 'HR', 'Sales') is far cleaner than writing three OR conditions — and even more so when the list grows to five or more values.
✅ Sample Employees Table used in all examples:-
| ID | Name | Department | City | Salary |
|---|---|---|---|---|
| 1 | ANNI | IT | Mumbai | 10000 |
| 2 | POOJA | IT | Pune | 90000 |
| 3 | RAJ | HR | Pune | 5000 |
| 4 | SUJAN | HR | Delhi | 8000 |
| 5 | MEENA | Sales | Mumbai | 12000 |
| 6 | RAVI | Finance | Chennai | 15000 |
✅ 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, ...):- A comma-separated list of values in parentheses.
✅ Text values:- Must be wrapped in single quotes — IN ('IT', 'HR').
✅ Number values:- No quotes needed — IN (1, 3, 5).
WHERE Department IN ('IT', 'HR') gives exactly the same result as WHERE Department = 'IT' OR Department = 'HR'. IN is just much cleaner to write and maintain.
✅ Example 1 – IN with Text Values (Departments)
Find all employees who work in IT, HR, or Sales.
✅ SELECT Query:-
SELECT * FROM Employees
WHERE Department IN ('IT', 'HR', 'Sales');
✅ Result:-
| ID | Name | Department | City | Salary |
|---|---|---|---|---|
| 1 | ANNI | IT | Mumbai | 10000 |
| 2 | POOJA | IT | Pune | 90000 |
| 3 | RAJ | HR | Pune | 5000 |
| 4 | SUJAN | HR | Delhi | 8000 |
| 5 | MEENA | Sales | Mumbai | 12000 |
✅ Example 2 – IN with Numbers (Employee IDs)
Find employees with ID 2, 4, or 6.
✅ SELECT Query:-
SELECT * FROM Employees
WHERE ID IN (2, 4, 6);
✅ Result:-
| ID | Name | Department | City | Salary |
|---|---|---|---|---|
| 2 | POOJA | IT | Pune | 90000 |
| 4 | SUJAN | HR | Delhi | 8000 |
| 6 | RAVI | Finance | Chennai | 15000 |
IN (2, 4, 6) is correct. IN ('2', '4', '6') would treat them as text, which may cause type mismatch errors in some databases.
✅ Example 3 – NOT IN (Exclude Multiple Values)
Find all employees who are NOT in the IT or Finance departments.
✅ SELECT Query:-
SELECT * FROM Employees
WHERE Department NOT IN ('IT', 'Finance');
✅ Result:-
| ID | Name | Department | City | Salary |
|---|---|---|---|---|
| 3 | RAJ | HR | Pune | 5000 |
| 4 | SUJAN | HR | Delhi | 8000 |
| 5 | MEENA | Sales | Mumbai | 12000 |
✅ Example 4 – IN with a Subquery
Find all employees who work in departments that have at least one employee earning more than 50000.
✅ SELECT Query:-
SELECT * FROM Employees
WHERE Department IN (
SELECT Department FROM Employees
WHERE Salary > 50000
);
✅ Result:-
| ID | Name | Department | City | Salary |
|---|---|---|---|---|
| 1 | ANNI | IT | Mumbai | 10000 |
| 2 | POOJA | IT | Pune | 90000 |
SELECT Department FROM Employees WHERE Salary > 50000 returns 'IT' (POOJA earns 90000). The outer query then finds all employees in the IT department — both ANNI and POOJA.
✅ Example 5 – IN Combined with AND
Find IT or HR employees who are based in Pune.
✅ SELECT Query:-
SELECT * FROM Employees
WHERE Department IN ('IT', 'HR')
AND City = 'Pune';
✅ Result:-
| ID | Name | Department | City | Salary |
|---|---|---|---|---|
| 2 | POOJA | IT | Pune | 90000 |
| 3 | RAJ | HR | Pune | 5000 |
✅ IN vs OR – Key Differences
| Feature | SQL IN | SQL OR |
|---|---|---|
| Same result? | ✅ Yes (on same column) | ✅ Yes (on same column) |
| Readability with many values | ✅ Clean — IN ('A','B','C','D') | ❌ Messy — four OR conditions |
| Works with subqueries | ✅ Yes — IN (SELECT ...) | ❌ No |
| Different columns | ❌ One column only | ✅ Any columns |
| NOT version | NOT IN (...) | Requires rewriting all conditions |
| Best for | Same column, multiple values | Different columns, mixed conditions |
✅ Key Points to Remember
✅ IN = shorthand for multiple OR conditions — cleaner and easier to maintain.
✅ Text values need single quotes — IN ('IT', 'HR') not IN (IT, HR).
✅ Numbers need no quotes — IN (1, 3, 5) is correct.
✅ NOT IN excludes all listed values — but beware of NULLs in the list.
✅ IN works with subqueries — dynamically filter based on another query result.
✅ Combine IN with AND — for powerful multi-column filtering in a single, readable query.
✅ NULL in NOT IN list = no rows returned — always exclude NULLs from NOT IN value lists.
✅ Common SQL IN Mistakes to Avoid
Wrong:
WHERE Department IN (IT, HR, Sales)Correct:
WHERE Department IN ('IT', 'HR', 'Sales')Without quotes, the database treats the values as column names and throws an error.
Wrong:
WHERE ID IN ('1', '3', '5') — treats numbers as text strings.Correct:
WHERE ID IN (1, 3, 5) — no quotes for numeric columns.
WHERE Department NOT IN ('IT', NULL) returns zero rows because SQL cannot compare NULL with NOT IN. Always ensure your NOT IN list contains no NULL values — filter NULLs separately with IS NOT NULL.
Wrong:
WHERE Department IN ('IT') OR City IN ('Pune') — this works but mixing AND/OR logic is cleaner here.IN only filters one column per use. To filter different columns, combine separate IN conditions with AND or OR.
✅ Frequently Asked Questions (FAQ)
WHERE Department IN ('IT','HR') is the same as WHERE Department = 'IT' OR Department = 'HR'.WHERE Department NOT IN ('IT','HR') returns all employees not in IT or HR. Beware — if the list contains NULL, NOT IN may return zero rows.WHERE ID IN (1, 3, 5) returns rows where ID equals 1, 3, or 5. Adding quotes to numbers can cause type mismatch errors.WHERE Department IN (SELECT Department FROM Employees WHERE Salary > 50000). This dynamically filters rows based on the subquery result — very powerful for real-world reporting.