SQL Tutorial

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.

💡 Real-world example: A manager needs a report showing only IT, HR, and Sales employees. Instead of writing three OR conditions, WHERE Department IN ('IT', 'HR', 'Sales') is cleaner, shorter, and gives exactly the same result.

Sample Employees Table used in all examples:-

Employees
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT9000Pune
3RAJHR5000Delhi
4SUJANHR8000Pune
5MEENASales12000Mumbai
6PRAMODFinance15000Bangalore
7NILESHSales7000Delhi

✅ 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);
ℹ️ Equivalent expression: 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:-

Result — IT and Sales Employees
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT9000Pune
5MEENASales12000Mumbai
7NILESHSales7000Delhi
💡 Explanation: Only employees in IT or Sales are returned. RAJ and SUJAN (HR) and PRAMOD (Finance) are excluded because their departments are not in the list. The IN operator checks each row and includes it only if the Department value matches any item in the list.

✅ 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:-

Result — Employees with Salary 5000, 9000, or 15000
IDNameDepartmentSalaryCity
2POOJAIT9000Pune
3RAJHR5000Delhi
6PRAMODFinance15000Bangalore
ℹ️ Note: Numbers in the IN list do not need single quotes. Only the employees whose salary exactly equals 5000, 9000, or 15000 are returned. ANNI (10000), SUJAN (8000), MEENA (12000), NILESH (7000) are not in the list so they are excluded.

✅ 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:-

Result — Employees NOT in IT or Finance
IDNameDepartmentSalaryCity
3RAJHR5000Delhi
4SUJANHR8000Pune
5MEENASales12000Mumbai
7NILESHSales7000Delhi
⚠️ NOT IN and NULL values: If the NOT IN list or subquery contains any NULL value, NOT IN returns NO rows at all — because comparing any value to NULL gives UNKNOWN, not TRUE or FALSE. If using NOT IN with a subquery, always add 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:-

Result — Departments with High Earner Employees
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT9000Pune
5MEENASales12000Mumbai
6PRAMODFinance15000Bangalore
7NILESHSales7000Delhi
ℹ️ How the subquery works: The inner query 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:-

Result — IT or HR Employees, Salary 5000–10000
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT9000Pune
3RAJHR5000Delhi
4SUJANHR8000Pune
💡 Combining operators: IN, AND, and BETWEEN work together seamlessly in a WHERE clause. PRAMOD is excluded (Finance, not IT/HR). MEENA and NILESH are excluded (Sales + salary not in both conditions).

✅ IN vs OR Comparison

Both give identical results when used on the same column. Choose based on readability.

FeatureIN OperatorOR Operator
ResultIdenticalIdentical
ReadabilityCleaner and shorterGets long with many values
3+ valuesIN ('IT','HR','Sales')= 'IT' OR = 'HR' OR = 'Sales'
Subquery support✅ Yes — IN (SELECT ...)❌ No
Performance (same column)Same as ORSame as IN
NOT versionNOT IN (...)<> 'x' AND <> 'y'
Works with NULL in list⚠️ NULL causes NOT IN to fail⚠️ NULL comparisons also fail
💡 Rule of thumb: Use IN when filtering a single column against 3 or more values — it is far more readable. Use OR when combining conditions across different columns, e.g., 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 quotesIN ('IT', 'HR'). Numbers do not — IN (5000, 9000).

✅ IN works with subqueriesWHERE 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 / BETWEENWHERE Department IN ('IT', 'HR') AND Salary BETWEEN 5000 AND 10000.

✅ Order inside IN does not matterIN ('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

❌ Mistake 1: Missing single quotes around text values
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.
❌ Mistake 2: Using NOT IN with a subquery that may return NULL
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)
❌ Mistake 3: Forgetting parentheses around the value list
Wrong: WHERE Department IN 'IT', 'HR' — syntax error.
Correct: WHERE Department IN ('IT', 'HR') — the value list must be inside parentheses.
❌ Mistake 4: Using IN to compare across different columns
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.
❌ Mistake 5: Very large IN lists hurting performance
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)

What does the SQL IN operator do?
The SQL IN operator filters rows where a column value matches any value from a specified list. It is shorthand for multiple OR conditions on the same column. For example, WHERE Department IN ('IT', 'HR', 'Sales') is equivalent to WHERE Department = 'IT' OR Department = 'HR' OR Department = 'Sales'.
What is the difference between SQL IN and OR?
Both return identical results when checking the same column against multiple values. IN is shorter and cleaner — especially with many values. OR becomes unwieldy with 5+ conditions. Additionally, IN can accept a subquery as its value source, which OR cannot do directly.
What is NOT IN in SQL?
NOT IN returns rows where the column value does NOT match any value in the specified list. Example: 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.
Can I use SQL IN with a subquery?
Yes. Replace the value list with a subquery: 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.
Does SQL IN work with NULL values?
IN ignores NULL values in comparisons — a NULL column value will not match anything in the list. For NOT IN, if the subquery or list contains any NULL, NOT IN returns no rows at all, because comparing any value with NULL gives UNKNOWN in SQL, not TRUE. Always use WHERE column IS NOT NULL in the subquery when using NOT IN.
Is SQL IN faster than multiple OR conditions?
For simple value lists, IN and OR produce the same execution plan and performance is identical. IN is preferred for readability and maintainability — especially with 3+ values. For very large value lists (hundreds of IDs), consider using a temporary table with a JOIN instead for better performance.

✍️ About the Author: Pramod Behera

Pramod Behera is a SAP and SQL educator with 10+ years of experience in enterprise software and database systems. He founded LearnToSAP.com to help beginners learn SAP and SQL concepts through clear, practical, real-world examples. His tutorials have helped thousands of students and IT professionals across India and beyond.