Skip to main content
SQL โ€ข LESSON 82

JOIN with Aggregation

How can we count employees in each department?

Intermediateโฑ 3 Minutesโญ 950 XP
๐Ÿค” THE QUESTION

How can we count employees in each department?

๐Ÿ’ก WHAT IS IT?

Combining LEFT JOIN with GROUP BY aggregates child records against parent dimensions accurately.

๐ŸŽฏ WHAT IS IT USED FOR?

Department headcounts including 0-employee divisions, customer order counts.

๐Ÿ’ป EXAMPLE
SELECT d.department_name, COUNT(e.employee_id) AS employee_count
FROM departments d
LEFT JOIN employees e
ON d.department_id = e.department_id
GROUP BY d.department_name;

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for JOIN with Aggregation.

  • โœ“ JOIN + GROUP BY
  • โœ“ Parent-child aggregation
  • โœ“ COUNT on child PK
  • โœ“ Department summaries