Skip to main content
SQL โ€ข LESSON 97

NOT IN Subquery

How can we find employees outside a set of selected departments?

Advancedโฑ 3 Minutesโญ 1100 XP
๐Ÿค” THE QUESTION

How can we find employees outside a set of selected departments?

๐Ÿ’ก WHAT IS IT?

NOT IN subqueries exclude records whose foreign key appears in the subquery's result set.

๐ŸŽฏ WHAT IS IT USED FOR?

Excluding specific business units, filtering out blacklisted accounts, non-member lookups.

๐Ÿ’ป EXAMPLE
SELECT name
FROM employees
WHERE department_id NOT IN (
    SELECT department_id
    FROM departments
    WHERE department_name IN ('HR', 'Finance')
);

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for NOT IN Subquery.

  • โœ“ NOT IN subquery
  • โœ“ Exclusion lists
  • โœ“ Department filtering
  • โœ“ Multi-level subqueries