Ravi Khatri
Ravi Khatri

Reputation: 151

Return employee salary greater than manger salary from a single all in one employees table

i am new to sql journey and got stuck on one query , i want to return employee having salary greater than their manager , only one table is there, there are employee having unique id

click here for my sample database

Upvotes: 1

Views: 88

Answers (2)

ravioli
ravioli

Reputation: 3833

I can't access your image link, but here is a simple example:

SELECT emp.name 
FROM employee emp 
INNER JOIN employee mgr ON emp.managerid = mgr.id AND emp.salary > mgr.salary

Upvotes: 1

Gordon Linoff
Gordon Linoff

Reputation: 1270401

I would do this as:

select e.*
from employees e
where e.salary > (select m.salary
                  from employees m
                  where m.id = e.employee_id
                 );

Upvotes: 1

Related Questions