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 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.

💡 Real-world example: A manager wants to see employees from IT, HR, and Sales departments only. Using 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:-

Employees
IDNameDepartmentCitySalary
1ANNIITMumbai10000
2POOJAITPune90000
3RAJHRPune5000
4SUJANHRDelhi8000
5MEENASalesMumbai12000
6RAVIFinanceChennai15000

✅ 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).

ℹ️ Equivalent to OR: 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:-

Result — IT, HR and Sales Employees
IDNameDepartmentCitySalary
1ANNIITMumbai10000
2POOJAITPune90000
3RAJHRPune5000
4SUJANHRDelhi8000
5MEENASalesMumbai12000
💡 Note: RAVI (Finance) is excluded because Finance is not in the IN list. All five other employees match at least one value in the list.

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

Result — Employees with ID 2, 4 or 6
IDNameDepartmentCitySalary
2POOJAITPune90000
4SUJANHRDelhi8000
6RAVIFinanceChennai15000
ℹ️ No quotes for numbers: When using IN with numeric values, never add quotes. 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:-

Result — Employees Outside IT and Finance
IDNameDepartmentCitySalary
3RAJHRPune5000
4SUJANHRDelhi8000
5MEENASalesMumbai12000
⚠️ NOT IN and NULL values: If any value in the NOT IN list is NULL, the query may return no rows at all. This is a common trap — always ensure your value list contains no NULLs when using NOT IN.

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

Result — Employees in Departments with High Earners
IDNameDepartmentCitySalary
1ANNIITMumbai10000
2POOJAITPune90000
ℹ️ How it works: The subquery 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:-

Result — IT or HR Employees in Pune
IDNameDepartmentCitySalary
2POOJAITPune90000
3RAJHRPune5000
💡 IN + AND is very powerful for real-world reporting. You can combine IN on one column with AND conditions on different columns to build precise, readable filters in a single query.

✅ IN vs OR – Key Differences

FeatureSQL INSQL 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 versionNOT IN (...)Requires rewriting all conditions
Best forSame column, multiple valuesDifferent columns, mixed conditions
💡 Rule of thumb: Use IN when filtering one column against multiple values. Use OR when filtering different columns with different conditions. Mixing IN with AND for multi-column filtering is the best real-world pattern.

✅ Key Points to Remember

✅ IN = shorthand for multiple OR conditions — cleaner and easier to maintain.

✅ Text values need single quotesIN ('IT', 'HR') not IN (IT, HR).

✅ Numbers need no quotesIN (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

❌ Mistake 1: Missing single quotes around text values
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.
❌ Mistake 2: Using quotes around number values
Wrong: WHERE ID IN ('1', '3', '5') — treats numbers as text strings.
Correct: WHERE ID IN (1, 3, 5) — no quotes for numeric columns.
❌ Mistake 3: NULL in the NOT IN list
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.
❌ Mistake 4: Using IN across different columns
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)

What does the SQL IN operator do?
The SQL IN operator filters rows where a column value matches any value in a specified list. It is a shorthand for multiple OR conditions: WHERE Department IN ('IT','HR') is the same as WHERE Department = 'IT' OR Department = 'HR'.
What is the difference between SQL IN and OR?
Both return the same result when checking the same column. IN is cleaner and shorter when you have many values. It also supports subqueries, which OR cannot. Use OR when filtering across different columns with different conditions.
What is SQL NOT IN?
NOT IN returns rows where the column value does NOT match any value in the list. Example: 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.
Can I use SQL IN with numbers?
Yes. IN works with any data type. For numbers, no quotes are needed: WHERE ID IN (1, 3, 5) returns rows where ID equals 1, 3, or 5. Adding quotes to numbers can cause type mismatch errors.
Can I use SQL IN with a subquery?
Yes. Replace the value list with a SELECT subquery: 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.
Does SQL IN work with NULL values?
NULL values are not matched by IN. If a column contains NULL, it will not appear in the result of IN or NOT IN. Use IS NULL or IS NOT NULL separately to handle NULL values in your queries.

✍️ 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.