Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Employee and Manager Join Query

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Employee and Manager Join Query. Start with the requirements and the one table on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Beaconfiresolution needs an employee directory showing each employee and the person they report to. The reporting hierarchy is stored in a single employee table.

Write a PostgreSQL query to return every employee's name and manager's name.

Requirements

  1. Use a self-join on the employee table to match each employee with their manager.
  2. Include employees who do not have a manager.
  3. Display No manager when an employee's manager_id is NULL.
  4. Sort the results by employee ID in ascending order.

Schema

employee
ColumnTypeDescription
employee_idPKINTEGERUnique employee identifier
employee_nameVARCHAR(100)Employee's full name
manager_idINTEGERReferences employee_id for the employee's manager
Tablesemployee
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results