Self Join Employees Table Department Comparison
Find employees who work in the same department as their manager.
sql
SELECT e.name FROM employees e JOIN employees m ON e.manager_id = m.id WHERE e.department_id = m.department_id;
This query performs a self-join on the "employees" table to compare the "department_id" of each employee with the "department_id" of their respective manager, returning the names of employees where these values match.
PromptDB can make mistakes. Please double-check responses.