Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Find the Second Highest Salary
00:00
5 left

Find the Second Highest Salary

MediumSQL · PostgreSQL

Problem

Find the second highest salary.

Asked in the Virtual Interview stage, SQL assessment section. Treat duplicate salary values as one salary level. If fewer than two distinct non-NULL salaries exist, return a single row with a NULL result.

Output

  1. Return one row with one column named second_highest_salary.
  2. Include the second highest distinct non-NULL salary, or NULL when it does not exist.
  3. The result contains exactly one row.

Schema

employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(100)Employee name
departmentVARCHAR(80)Employee department
salaryNUMERIC(12,2)Annual employee salary
Tablesemployees
Interviewer

Your question is Find the Second Highest Salary. 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.