Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

Leetcode Department Highest Salary problem solution

YASH PAL, 31 July 202419 January 2026

In this Leetcode Department Highest Salary problem solution, the Employee table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id. The Department table holds all departments of the company.

Write a SQL query to find employees who have the highest salary in each of the departments. For the above tables, your SQL query should return the following rows (order of rows does not matter).

+————+———-+——–+

| Department | Employee | Salary |

+————+———-+——–+

| IT         | Max      | 90000  |

| IT         | Jim      | 90000  |

| Sales      | Henry    | 80000  |

+————+———-+——–+

Leetcode Department Highest Salary problem solution

Leetcode Department Highest Salary problem solution in Oracle.

select d.Name as Department, e.NAME as Employee, e.SALARY as Salary  from Employee e 
inner join Department d
on e.DepartmentId=d.Id
inner join
(
select   
DepartmentId ,
max(Salary) as Salary
from Employee 
group by  DepartmentId
) a
on e.Salary=a.Salary and e.DepartmentId=a.DepartmentId

Department Highest Salary problem solution in MySQL.

SELECT d.Department, e.Name as Employee, e.Salary
FROM (
    SELECT d.Name AS Department, d.Id AS dId, MAX(e.Salary) AS Salary
    FROM Employee e
    LEFT JOIN Department d
    ON e.DepartmentID = d.Id
    GROUP BY Department, dId
    ) d
INNER JOIN Employee e
ON d.Salary = e.Salary
AND d.dId = e.DepartmentId

Problem solution in C++.

select c.Name as Department, a.Name as Employee, a.Salary as Salary from (
select * from Employee
) a
inner join (
select max(Salary) as Salary, DepartmentId from Employee group by DepartmentId
) b on a.Salary = b.Salary and a.DepartmentId = b.DepartmentId
left join (
select * from Department
) c on a.DepartmentId = c.Id where c.Name is not null

coding problems solutions Leetcode Problems Solutions Leetcode

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes