SQLSQL
#13

Self-Joins for Organizational Hierarchy in SQL

MediumHonda
Interview Question #13
Asked at Honda

Given an `employees` table (emp_id, emp_name, manager_id), write a query to list each employee along with their direct manager's name. If an employee has no manager (e.g. CEO), display 'Top Executive'.

Input Table: employees
4 rows preview
emp_idemp_namemanager_id
1Rajesh MehtaNULL
2Kaushal Kumar1
3Pooja Sharma1
4Ankit Verma2
Expected Output Structure4 rows
emp_idemployee_namemanager_name
1Rajesh MehtaTop Executive
2Kaushal KumarRajesh Mehta
3Pooja SharmaRajesh Mehta
4Ankit VermaKaushal Kumar
Interview Context

Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.

SQLPostgreSQL 15
Ready to execute

Click "Run Query" or press Ctrl + Enter to test your query.

Output will be verified against the test dataset.

Chat with us