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
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
- FROM staff e: the employee copy of the table.
- 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.
- 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
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;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.