Skip to main content
SQL โ€ข LESSON 14

IN with Subqueries

How can we filter records against a dynamic list returned by another table?

Intermediateโฑ 2 Minutesโญ 240 XP
๐Ÿค” THE QUESTION

How can we filter records against a dynamic list returned by another table?

๐Ÿ’ก WHAT IS IT?

The IN operator with a subquery matches values against a multi-row column generated dynamically.

๐ŸŽฏ WHAT IS IT USED FOR?

Filtering employees in specific branch locations, active customer accounts, or product categories.

๐Ÿ’ป EXAMPLE
SELECT *
FROM employees
WHERE department IN (
  SELECT department
  FROM departments
  WHERE location = 'New York'
);

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for IN with Subqueries.

  • โœ“ IN Subquery
  • โœ“ Multi-row subquery
  • โœ“ Cross-table filtering
  • โœ“ WHERE IN