Skip to main content
SQL • LESSON 82

JOIN with Aggregation

How can we count employees in each department?

Intermediate3 Minutes950 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