Learn with Abdou

Chapter 7 · Concept 4 of 6 · Practice

The staff chart loses its top row

one table, two roles · level 1 of 6

Opening your saved work…

Sign in to save across devices → · Download your guest work before switching accounts.

The staff chart loses its top row · one table, two roles · level 1 of 6

Who reports to whom

Level 1: Watch it answered · Exercise 1 of 1

Every staff member with their supervisor's id, including the director who has none. Watch the self-join, then run it.

Data: Twin Ports Tool Library.

Why it works, clause by clause

  1. FROM staff e: the employee copy of the table.
  2. LEFT JOIN staff m ON m.id = e.supervisor_id: the manager copy, paired where its id equals the employee's supervisor_id. LEFT, so the director with a NULL supervisor_id keeps her row.
  3. The two id columns on the right agree on every matched row and are NULL together on the director's row, which proves the pairing.

From the reading: A table meets itself, paragraph 1

The queryOpening the database…
SELECT e.id AS employee_id, e.supervisor_id, m.id AS matched_supervisor
FROM staff e
LEFT JOIN staff m ON m.id = e.supervisor_id
ORDER BY e.id;
Open in the playground

Query results

Run it to see the result here.

Run it to see the result here.

Practice here is evidence for you and your instructor, never a grade. Grades live in Canvas.