Code RoomSecond-highest salary by department
HardPrep Room Coding #5054

Second-highest salary by department

SQLAlgorithms & data structuresSenior–Staff~14 min

For each department, return the employee with the second-highest salary. Give `department`, `name` and `salary`, ordered by department name.

Departments with fewer than two recorded salaries simply do not appear.

What a strong answer looks like

Say what the query is meant to return before you write it, and name the shape of the answer: how many rows, grouped by what. Then watch the NULLs and the duplicates, because that is where most of these are lost.

Run onlyA query runs as one statement, so there is nothing to step through. Run it and read the rows.

0:00 of about 14 min

Expected, in this order

departmentnamesalary
EngineeringGrace165000

Your result

Run your query to compare.

1 more set of rows are waiting. Free with an account.