← Back to Joins
Question 97
Who Heads Each Department
Who Heads Each Department
For each department, show the instructor who heads it. Returndepartment(the department'sname, aliased), then the head'sfirst_nameandlast_name. The join column ishead_instructor_id, which is not the usual direction: the department row points at the instructor. Business has no head yet and must not appear. Sort bydepartment.
Expected result:
+------------------+------------+-----------+ | department | first_name | last_name | +------------------+------------+-----------+ | Biology | Amara | Diallo | | Computer Science | Grace | Okafor | | English | Helen | Brooks | | Fine Arts | Rafael | Moreno | | Mathematics | Samuel | Whitaker | +------------------+------------+-----------+ 5 rows
Hints3 available
Sign in to use hintsTopics:
Joins
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sel, ins, desc)
Results
Run your SQL to see every statement's output here, then how it compares with the expected answer.
Not sure what is in a table? SHOW TABLES lists them and DESCRIBE students shows the columns — or open the database browser on the left.