Skip to content

The LEFT JOIN that became an INNER JOIN

You want every department, with the number of employees in it, including departments with nobody.

sql SELECT d.name, COUNT(e.id) FROM Department d LEFT JOIN Employee e ON e.dept_id = d.id WHERE e.salary > 30000 GROUP BY d.name;

Empty departments are missing from the result. Why?