Skip to main content
Admissions guidance, study banks, and career tools โ€” get started on Shalyam

Employees per Department Including Empty Ones

Return every department name with its employee count, including departments with zero employees. Order by department name.

Table schema

Departments(id INT PRIMARY KEY, name VARCHAR(50))
Employees(id INT PRIMARY KEY, name VARCHAR(50), department_id INT)

Sample data

Departments:
id | name
1 | Engineering
2 | HR
3 | Legal

Employees:
id | name | department_id
1 | A | 1
2 | B | 1
3 | C | 2

Discussion

No discussions yet.

Rewards ยท v2.1

Join Shalyam Newsletter

Get exclusive insights with every issue: education, research and innovation news.

One email a week. Unsubscribe any time.