Knowee
Questions
Features
Study Tools

Write an SQL query to find the employees who earn more than their managers.

Question

Write an SQL query to find the employees who earn more than their managers.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a step-by-step guide on how to write an SQL query to find the employees who earn more than their managers.

Assuming we have two tables: employees and managers. The employees table has columns id, name, salary, and manager_id. The managers table has columns id, name, and salary.

Here is the SQL query:

SELECT e.name AS employee_name, e.salary AS employee_salary, m.name AS manager_name, m.salary AS manager_salary
FROM employees e
JOIN managers m ON e.manager_id = m.id
WHERE e.salary > m.salary;

Here is the step-by-step explanation:

  1. SELECT e.name AS employee_name, e.salary AS employee_salary, m.name AS manager_name, m.salary AS manager_salary: This line is selecting the names and salaries of both the employees and their managers.

  2. FROM employees e: This line is specifying that we are selecting from the employees table and we are aliasing it as e for simplicity.

  3. JOIN managers m ON e.manager_id = m.id: This line is joining the employees table with the managers table where the manager_id in the employees table matches the id in the managers table. We are aliasing managers as m for simplicity.

  4. WHERE e.salary > m.salary: This line is the condition that the employee's salary must be greater than their manager's salary.

This query will return a list of employees who earn more than their managers, along with their salaries and their managers' names and salaries.

This problem has been solved

Similar Questions

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

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

1. Write a query to find all employees who earn more than the average salary.2. Write a query to retrieve the names of employees who work in the same department as ‘John’.3. Write a query to display the second highest salary from the Employee table.4. Write a query to find all customers who have made more than five orders.5. Write a query to count the number of orders placed by each customer.6. Write a query to retrieve the list of employees who joined in the last 6 months.7. Write a query to find the total sales amount per product.8. Write a query to list all products that have never been sold.9. Write a query to update the salary of employees based on their performance rating.10. Write a query to delete duplicate rows from a table.11. Write a query to find the second highest salary in a company without using the MAX function twice.12. Write a query to identify the top 10 customers who have not placed an order in the last year.13. Create a query to compute the year-over-year growth rate of revenue for each product category.14. Write a query to join three tables and filter the results to show only records that exist in exactly two of the tables.15. Construct a query to find the median sales amount for each region.16. Write a query to calculate the retention rate of customers over a given time period.17. Write a query to find duplicate records in a table and count the number of duplicates for each unique record.18. Create a query to find employees who have been with the company for more than 5 years but have never been promoted.

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

1/3

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.