Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Second-Highest Salary Without LIMIT
00:00
5 left

Second-Highest Salary Without LIMIT

EasySQL · PostgreSQL

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
Interviewer

Your question is Second-Highest Salary Without LIMIT. Start with the requirements and the one table in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.