Practice / joins

Who Reports to Whom

medium

An HR tool stores an org chart in one employees table: each person has an id, a name, and an optional manager_id pointing at another employee's id.

employees

Your task: return employee and manager — each person's name and their manager's name. People with no manager can be dropped.

Assign your answer DataFrame to result. Row order doesn't matter.

employeesinput DataFrame

Schema
columntype
idlong
namestring
manager_idlong
Sample rows
idnamemanager_id
1Raenull
2Sol1
3Uma1
4Ivo2
Expected output shape
employeemanager· 3 rows
Hint

Alias the table twice and join it to itself: e = employees.alias("e"), m = employees.alias("m"), then join e.manager_id == m.id. Select e.name as the employee and m.name as the manager.

Lesson refresher

This problem builds on Joins (~8 min). Pop it open in a new tab if you want a quick recap.

Loading editor…
Hit Run to execute your code and see the output here.