Beginner

179. NOT IN Operator

Learn how NOT IN excludes records matching values in a specified list.

📘 Lesson 179 of 728 ⏱ 8 min 🎯 Intermediate

The NOT IN operator returns rows where an expression does not match any value in the specified list or subquery result.

NOT IN is useful when business analysis requires excluding selected categories or values.

Find employees who are not working in IT, Finance, or HR.

SQL
SELECT
    EmployeeName,
    Department
FROM Employees
WHERE Department NOT IN ('IT', 'Finance', 'HR');

NOT IN is useful for exclusion filters, exception reporting, customer segmentation, and operational analysis.

  • NOT IN excludes listed values.
  • It can replace multiple not-equal conditions.
  • It can work with subqueries.
  • NULL values require careful consideration.
  • It is useful for exclusion logic.
What does NOT IN do?

NOT IN returns rows whose values do not match any value in the specified list or subquery result.

Why should NULL be considered with NOT IN?

NULL introduces three-valued logic and can cause NOT IN with a subquery to behave unexpectedly.

Have you finished this lesson?

Introduction to SQL – All Lessons