Skip to main content
SQL • LESSON 96

IN Subquery

How can we find employees working in departments located in New York?

Advanced3 Minutes1090 XP
🤔 THE QUESTION

How can we find employees working in departments located in New York?

💡 WHAT IS IT?

The IN subquery checks whether a foreign key matches any ID returned by a secondary query.

🎯 WHAT IS IT USED FOR?

Location-based filtering, customer segment filtering, dynamic category inclusion.

💻 EXAMPLE
SELECT name
FROM employees
WHERE department_id IN (
    SELECT department_id
    FROM departments
    WHERE location = 'New York'
);

🎯 Mission Objectives

Practice typing production-grade SQL code for IN Subquery.

  • IN subquery
  • Dynamic list matching
  • Relational subqueries
  • Location lookups