Second Highest Salary
EasySQLSQL
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Table employees:
id INTEGER primary key
name TEXT
salary INTEGER
Return the second highest distinct salary. If there is no second distinct salary, return a single row containing NULL.
Columns: the salary.
The result is always exactly one row.
Examples
Input: employees
id | name | salary
1 | Ana | 300
2 | Ben | 200
3 | Cho | 300
Output: 200
The two 300s are one distinct salary, so 200 is second.
Constraints
- Several people can share a salary.
- The table can have one row, or none.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.