Self Join Employees Table for Managers

Find all employees along with their manager's name.

sql

SELECT e.name AS employee_name, m.name AS manager_name FROM employees e LEFT JOIN employees m ON e.manager_id = m.id;

This query performs a self-join on the "employees" table to associate each employee with their corresponding manager by matching the "manager_id" of the employee to the "id" of the manager.

PromptDB can make mistakes. Please double-check responses.