runtime
29 / 88

task Self joins · medium

Earning more than the manager

Return employee, employee_salary, manager and manager_salary for employees who earn strictly more than their direct manager.

what to return

Columns
employeeemployee_salarymanagermanager_salary in this order
Rows
2 rows · any order
Watch for
Equal salaries don't count.
Employees without a manager can't qualify.
Skill
Join a table to itself through a parent key. Refresher: Self-joins & referral relationships →

expected result

Your query should return exactly these columns and values. Run it and compare.

expected result2 rows · any order
employeeemployee_salarymanagermanager_salary
Elif Kaya145000Dev Patel140000
Hugo Brandt185000Bruno Costa180000

all 2 rows

data you can query

Sample rows from each table. Each column shows its type underneath; → marks a link to another table.

employees7 columns · 20 rows
idinteger · keynametextmanager_idinteger → employeesdepartment_idinteger → departmentstitletextsalaryrealhired_attext
1Ada MorenoNULLNULLCEO2500002019-03-01
2Bruno Costa11VP Engineering1800002019-06-15
3Carmen Diaz12VP Sales1500002020-01-10
4Dev Patel21Engineering Manager1400002020-05-04
5Elif Kaya41Senior Engineer1450002021-02-01

showing 5 of 20 rows

solution.sql
 

Hints and the answer are always available. Using them counts the question as solved with help.