Skip to interview prep
Apexed

Second-highest distinct salary

SubqueriesMedium

Return the second-highest distinct salary as salary. (Two people sharing the top salary do not count twice.)

Tables

  • departments: id, name
  • employees: id, name, department_id, manager_id, salary, hired_on

Row order does not matter. Column names do not have to match, but the number of columns and the values do.

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run your query. It is checked against the expected result on the same data.

Solution

Queries run only in your browser on a private SQLite database (sql.js from a public CDN). Nothing is sent to Apexed.

Second-highest distinct salary: SQL interview practice — Apexed