Default Image

Employees Without a Manager

Employees Without a Manager Easy
The staff table contains employee information. Each employee may have a manager_id that references another employee's id. A NULL manager_id means the employee has no manager (they are a top-level executive).

Write a query using a LEFT JOIN or subquery to find all employees who do not have a manager listed in the staff table.

Return: id, name, title.
Order by id ascending.
staff
CREATE TABLE staff (
    id         INT PRIMARY KEY,
    name       VARCHAR(100) NOT NULL,
    title      VARCHAR(100) NOT NULL,
    manager_id INT DEFAULT NULL
);
INSERT INTO staff VALUES
(1,  'Sandra Lee',    'CEO',               NULL),
(2,  'Tom Hughes',    'CTO',               1),
(3,  'Maya Patel',    'VP Engineering',    2),
(4,  'James King',    'Senior Engineer',   3),
(5,  'Lena Wood',     'Engineer',          3),
(6,  'Chris Adams',   'CFO',               1),
(7,  'Nina Russo',    'Finance Manager',   6),
(8,  'Peter Chase',   'Analyst',           999),
(9,  'Diana Fox',     'CMO',               NULL),
(10, 'Ryan Stone',    'Marketing Lead',    9);

Log in to see your submissions.

  1. Self-join the table. Left join where manager_id IS NULL or the manager doesn't exist in the table.
SQL
Write a query and click Run to see results.