The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.IdNameSalaryManagerId1Joe7000032Henry8000043Sam60000NULL4Max90000NULLGiven the Employee table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.EmployeeJoeOptionsselect e.Name as Employee to Employeefrom e inner join Employee has m on e.ManagerId = m.id where e.Salary > m.Salary;select e.Name as Employee from Employeeas e inner join Employee as m on e.ManagerId = m.idwhere e.Salary > m.Salary;select e.Name as Employeefrom Employee on e.ManagerId = m.id where e.Salary > m.Salary;select e.Name as Employee from Employeeas e inner join Employee
Question
The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.IdNameSalaryManagerId1Joe7000032Henry8000043Sam60000NULL4Max90000NULLGiven the Employee table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.EmployeeJoeOptionsselect e.Name as Employee to Employeefrom e inner join Employee has m on e.ManagerId = m.id where e.Salary > m.Salary;select e.Name as Employee from Employeeas e inner join Employee as m on e.ManagerId = m.idwhere e.Salary > m.Salary;select e.Name as Employeefrom Employee on e.ManagerId = m.id where e.Salary > m.Salary;select e.Name as Employee from Employeeas e inner join Employee
Solution
The correct SQL query to find employees who earn more than their managers would be:
SELECT e.Name AS Employee
FROM Employee AS e
INNER JOIN Employee AS m
ON e.ManagerId = m.id
WHERE e.Salary > m.Salary;
This query works by joining the Employee table to itself (once as 'e' for the employee and once as 'm' for the manager). It then compares the salary of each employee to the salary of their manager, and returns the names of employees who earn more.
Similar Questions
Write an SQL query to find the employees who earn more than their managers.
Write a SQL query considering below schema. Create tables with Primary Key, foreign key constraints in given schemas.Manager (mid, eid, mname)Department (did, mid, dname, location)Employee (eid, ename, mobile, salary, joining_date, mid)i.Give the name and salary of employees whose salary are greater than each and every employees who are working under managerid 14.ii.Give the name of employees who have not assigned any department.iii.Give the employee names whose location is Kota.iv.Give the name of manager along with count of employees assigned to him/her in descending order
Write SQL QueriesEmployee TableDepartment Table1. Get the list of employees whose salary is more than 20K and are in HR department.2. Get the salary being paid to each Department.3. Get the employees with the third highest salary.4. Name and designation of the employees who don't have any manager
Find the following table EmployeeDetails, with the attributes EmployeeID, EmpName, Designation, Salary, DeptNo. You are assigned to a task of providing the solution to the operations department by writing the query which displays the employeeID and the Designation of all the employees whose Salaries are more than the Salary of employees designated as ManagerC
The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.IdNameDepartmentManager ID101JohnAnull102DanA101103JamesA101104AmyA101105AnneA101106RonB101Given the Employee table, write a SQL query that finds out managers with at least 5 direct report. For the above table, your SQL query should return:NameJohnNote:No one would report to himself.Optionsselect Namefrom Employeewhere Id in ( select ManagerId from Employee group by ManagerId having count(*) >= 5);select Namefrom Employeewhere Id in ( select ManagerId from Employee having count(*) >= 5);select Name select ManagerId from Employee group by ManagerId having count(*) >= 5);select Namefrom Employeewhere Id in ( from Employee group by ManagerId having count(*) >= 5);
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.