Employees Earning More Than Their Managers — Day 92(SQL)

Photo by Mufid Majnun on Unsplash

Today’s question is a SQL question. Let us look into the problem statement.

181. Employees Earning More Than Their Managers

The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.

Given 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.

We have a table that contains some information about the employees working in an organization. Each employee has an Id, Name, Salary, and ManagerId. If we observe the values in the ManagerId column is from the Id column in the table. We need to find those employees who earn more than their manager.

How would we know about the salaries of the managers? Well, we know the salary of each employee, we just need to self join the Employee table to get to know the salaries of managers. From there, we can check if the employees earn more than their managers.

Let us look into the code snippet.

Software Engineer. Find me @ www.linkedin.com/in/annamariya-jt