Back to SQL Notes
Topic #85

SQL IN Operator

IN checks whether a value matches any value in a given list — a shorter, cleaner alternative to a chain of OR conditions.

Syntax

WHERE column IN (value1, value2, value3)

Sample Table: employees

namedepartment
AmanEngineering
RiyaMarketing
NehaDesign
KaranSales

Example

SELECT name FROM employees
WHERE department IN ('Engineering', 'Design');

Same result as:

WHERE department = 'Engineering' OR department = 'Design';

but far easier to read — and to extend — once the list grows past two items.

NOT IN

SELECT name FROM employees
WHERE department NOT IN ('Sales', 'Marketing');

IN with a Subquery

SELECT name FROM employees
WHERE department IN (
    SELECT department FROM departments WHERE region = 'North'
);

This is one of the most common real-world uses of IN — filtering against a dynamic list produced by another query. Full coverage in Subquery in WHERE.

Practical Use Case

Filtering against a known, finite set of values — statuses ('pending', 'shipped', 'delivered'), specific IDs, or a handful of category names.

Common Mistakes

  • NOT IN with a subquery that can return NULL — if the subquery's result set contains even one NULL, the whole NOT IN comparison can return no rows at all, which surprises almost everyone the first time they hit it. Prefer NOT EXISTS when the subquery might contain NULLs.
  • Using IN with a very large list (thousands of values) instead of joining against a proper table — IN is fine for a handful of literals, not as a substitute for a join

Interview Relevance

The NULL trap with NOT IN above is a favorite "gotcha" interview question — knowing it (and reaching for NOT EXISTS as the fix) is a strong signal of real SQL experience, not just textbook knowledge.

Practice Question

Rewrite WHERE status = 'pending' OR status = 'processing' OR status = 'shipped' using IN.

Want to go beyond the notes?

Join Coding Now Tech Institute's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

SQL IN Operator – FAQs

Quick answers about learning SQL IN Operator in SQL.

This free note from Coding Now Tech Institute explains SQL IN Operator in SQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every SQL topic on Coding Now Tech Institute, including SQL IN Operator, is 100% free with no signup required.
With focused practice, most students grasp SQL IN Operator in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now