Self Join Employees Table Salary Comparison

Find employees who earn less than their manager.

sql

SELECT e.name FROM employees e JOIN employees m ON e.manager_id = m.id WHERE e.salary < m.salary;

This query performs a self-join on the "employees" table to compare the "salary" of each employee with the "salary" of their respective manager, returning the names of those who earn less.

PromptDB can make mistakes. Please double-check responses.