Employee and manager

MediumSelf joinsHR analytics

The problem

List every employee with their manager's name. Name the columns employee and manager.

Employees without a manager must still appear, with manager shown as NULL.

Tables · Company directory

Click a table or column name to insert it into your query.

  • INTEGER · primary key
  • TEXT
Sample rows (4 total)
Sample rows from departments
dept_iddept_name
1Engineering
2Analytics
3Sales
4HR

  • INTEGER · primary key
  • TEXT
  • INTEGER · → departments, can be NULL
  • INTEGER · → employees.emp_id, NULL for top managers
  • INTEGER · rupees per year
Sample rows (12 total)
Sample rows from employees
emp_idnamedept_idmanager_idsalary
1Anita Rao1NULL260000
2Bhavin Shah11180000
3Chitra Menon11180000
4Deepak Verma12140000
5Esha Gupta2NULL220000

Next: Top earner per department →

Ctrl/⌘ + Enter runs the query. Table and column names are suggested as you type. Press Esc then Tab to leave the editor with the keyboard.

Expected output (12 rows)
Expected output
employeemanager
Anita RaoNULL
Bhavin ShahAnita Rao
Chitra MenonAnita Rao
Deepak VermaBhavin Shah
Esha GuptaNULL
Farhan AliEsha Gupta
Gita PillaiEsha Gupta
Harsh VoraFarhan Ali
Imran SheikhNULL
Jaya BoseImran Sheikh
Kiran DuttaImran Sheikh
Lata MenonNULL

Row order doesn’t matter for this question. Numbers are compared with a tiny tolerance; text must match exactly.

Stuck?

Stored on this device only. Your latest query and “solved” status are remembered in this browser only. They don’t sync between devices, and clearing your browser data removes them.