Databases · Junior · Question 72 of 75
Table employees(id, name, manager_id) stores each employee's manager. How do you list employees with their manager's name?
- 1
SELECT name, manager_id.name FROM employees - ✓Correct answer: Join the table with itself:
FROM employees e LEFT JOIN employees m ON m.id = e.manager_id - 3It's impossible without a second table
Explanation
This is a self-join; aliases make the two roles clear. LEFT JOIN keeps the top manager, who has no manager.