Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to SQL Notes
Topic #206

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.

Related SQL Notes

Want to go beyond the notes?

Join CodingNow's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →