Employees Who Out-Earn Their Manager
In employees, manager_id refers to another row of the same table. Find employees whose salary is strictly greater than their direct manager's salary. Ignore employees without a manager, or whose manager is not in the table.
Return columns employee_name, manager_name. Row order does not matter.
Schema
CREATE TABLE employees ( emp_id INTEGER PRIMARY KEY, name TEXT NOT NULL, salary INTEGER NOT NULL, manager_id INTEGER );
Sample data
employees
| emp_id | name | salary | manager_id |
|---|---|---|---|
| 1 | Nour | 20000 | NULL |
| 2 | Owen | 12000 | 1 |
| 3 | Paz | 21000 | 1 |
| 4 | Qadir | 12500 | 2 |
| 5 | Rhea | 11000 | 2 |
| 6 | Stan | 9000 | 3 |
Hint 1
Join the table to itself: one copy for employees, one for managers.
Hint 2
An inner join drops employees whose manager_id has no matching row.
Good practice for: Data Analyst, Backend Developer, Business Analyst, Database Administrator
SQL (SQLite)
Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.