Calculate Salary Difference Using Self Join

Find the difference between each employee's salary and their manager's salary.

sql

SELECT e.name AS employee_name, e.salary - m.salary AS salary_difference FROM employees e JOIN employees m ON e.manager_id = m.id;

This query performs a self-join on the "employees" table to compare the "salary" of each employee with the "salary" of their respective manager, identified by the "manager_id" foreign key.

PromptDB can make mistakes. Please double-check responses.