Find Highest Paid Employee Per Department

Find the highest-paid employee in each department.

sql

SELECT department_id, name, salary FROM employees e1 WHERE salary = ( SELECT MAX(salary) FROM employees e2 WHERE e1.department_id = e2.department_id );

This query uses a correlated subquery to identify the maximum salary within each department and filters the employees table to return only those whose salary matches that maximum value for their respective department.

PromptDB can make mistakes. Please double-check responses.