Skip to main content
SQL • LESSON 14

IN with Subqueries

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

Intermediate2 Minutes240 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