Find the Highest-Paid Employee in Each Department
Otter.AiData Engineer · Technical ScreenLast updated
Work through a tie-aware PostgreSQL problem that finds every highest-paid employee in each department. It assesses relational reasoning, correct joins, duplicate-name handling, and precise output semantics without assuming a single winner.
The interview report explicitly identified the “Department Highest Salary” SQL exercise. Use the following self-contained PostgreSQL schema:
departments
-----------
department_id BIGINT PRIMARY KEY
name TEXT NOT NULL
employees
---------
employee_id BIGINT PRIMARY KEY
name TEXT NOT NULL
salary NUMERIC NOT NULL
department_id BIGINT NOT NULL REFERENCES departments(department_id)
Write one PostgreSQL query that returns every employee whose salary equals the highest salary in that employee's department.
Return exactly these columns:
department: the department nameemployee: the employee namesalary: the employee salary
If several employees tie for the highest salary in a department, return all of them. Departments with no employees do not appear. Do not assume department names or employee names are unique. The relative order of returned rows does not matter.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.