Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Second-Highest Salary Without LIMIT

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Second-Highest Salary Without LIMIT. Start with the requirements and the one table on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Persistent Systems wants to identify the second-highest distinct salary in its engineering workforce. Write a PostgreSQL query using the employees table, without using the LIMIT keyword.

Requirements

  1. Return the second-highest distinct non-NULL salary as second_highest_salary.
  2. Handle duplicate salaries correctly. If multiple employees share the highest salary, the next lower distinct salary is still the answer.
  3. Return NULL if there is no salary below the maximum salary.
  4. Do not use LIMIT.

Schema

employees
ColumnTypeDescription
employee_idPKINTEGERUnique employee identifier
employee_nameVARCHAR(100)Employee's full name
departmentVARCHAR(80)Employee's department
salaryNUMERIC(10,2)Annual salary
Tablesemployees
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results