Interview Questions/SQL/Highest Paid Employee Per Department

Highest Paid Employee Per Department

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Highest Paid Employee Per Department

You are given a table of employees. Each employee has a name, a department, a salary, and a hire date. Write a SQL query to find the highest-paid employee(s) in each department. If multiple employees share the same maximum salary in a department, return all of them. Return the result ordered by department, then name. Table: Employees

Column NameTypeDescription
idINTPrimary key
nameVARCHAREmployee name
departmentVARCHARDepartment name
salaryINTAnnual salary
hire_dateDATEDate employee was hired

Examples

Example 1

For each department, find the employee(s) whose salary equals the maximum salary in that department.

Approach hint

Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

query.sql