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

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.

`+----+-------+--------+-----------+| Id | Name  | Salary | ManagerId |+----+-------+--------+-----------+| 1  | Joe   | 70000  | 3         || 2  | Henry | 80000  | 4         || 3  | Sam   | 60000  | NULL      || 4  | Max   | 90000  | NULL      |+----+-------+--------+-----------+`

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.

`+----------+| Employee |+----------+| Joe      |+----------+`

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.

`SELECT A.Name AS EmployeeFROM Employee A, Employee BWHERE A.Salary > B.SalaryAND A.ManagerId = B.Id;`

## More from Annamariya Tharayil

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

## How Relevant Is Django in a World of Frontend Frameworks and With the Trends of 2021?

Get the Medium app