Skip to main content
SQL โ€ข LESSON 96

IN Subquery

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

Advancedโฑ 3 Minutesโญ 1090 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