Return each employee alongside their manager's name. Top-level employees (NULL manager_id) or employees whose manager is missing from the table get a NULL manager_name. Return emp_id, name, manager_name. Row order does not matter.
| emp_id | name | dept | salary | manager_id | hire_date |
|---|---|---|---|---|---|
| 1 | Anil Kapoor | Engineering | 95000 | NULL | 2019-04-01 |
| 2 | Meera Nair | Engineering | 72000 | 1 | 2020-07-15 |
| 3 | Rahul Verma | Sales | 48000 | 5 | 2021-01-10 |
| 4 | Divya Menon | Engineering | 72000 | 1 | 2022-03-21 |
| 5 | Suresh Patil | Sales | 81000 | NULL | 2018-11-05 |
| 6 | Asha Rao | HR | 55000 | 5 | 2023-02-01 |
| emp_id | name | manager_name |
|---|---|---|
| 1 | Anil Kapoor | NULL |
| 2 | Meera Nair | Anil Kapoor |
| 3 | Rahul Verma | Suresh Patil |
| 4 | Divya Menon | Anil Kapoor |
| 5 | Suresh Patil | NULL |
| 6 | Asha Rao | Suresh Patil |
| emp_id | name | dept | salary | manager_id | hire_date |
|---|---|---|---|---|---|
| 11 | Harish Kumar | Finance | 60000 | NULL | 2017-06-01 |
| 12 | Lakshmi Iyer | Finance | 60000 | 11 | 2019-09-12 |
| 13 | Akash Jain | Finance | 45000 | 11 | 2021-02-02 |
| 14 | Ramesh | Ops | 52000 | 11 | 2022-08-30 |
| emp_id | name | manager_name |
|---|---|---|
| 11 | Harish Kumar | NULL |
| 12 | Lakshmi Iyer | Harish Kumar |
| 13 | Akash Jain | Harish Kumar |
| 14 | Ramesh | Harish Kumar |
Return exactly emp_id, name, manager_name — one row per employee.
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
{{ totalCount }} questions · {{ shHardPct }}% Hard. Real PySpark DataFrame and Spark SQL interview questions. Write PySpark in your browser on TechTown’s Spark engine, run sample tests, then submit against hidden tests.
Guests can solve {{ freeLimit }} problems for free. Log in or sign up (free) to unlock everything, keep your streak and appear on the leaderboard. New to a topic? Learn it first in the Spark course.
{{ p.statement }}
{{ p.constraints }}
No submissions yet. Press Submit to judge your code against all tests.
The model solution and step-by-step explanation unlock when you solve this problem or after 3 unsuccessful submissions ({{ shFailsLabel }}). Struggling? Try the hints on the Question tab first.
{{ p.solution }}
Write real PySpark: from pyspark.sql import functions as F, Window, spark.sql(...). It runs in your browser on a lightweight Spark engine, and the same code runs unchanged on Databricks or any Spark cluster. Use df.show() or print() to debug.
Create your free TechTown account to unlock every problem, track your progress, bookmark questions and keep preparing for interviews.