Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Fourth Highest Salary in SQL
00:00
5 left

Fourth Highest Salary in SQL

MediumSQL · PostgreSQL

Problem

Write a function to identify the fourth highest salary in an employee database.

Assume that "fourth highest" means the fourth-highest distinct non-NULL salary. Return every employee who earns that salary. Employees with NULL salaries must not be considered.

Output

  1. One row per employee earning the fourth-highest distinct salary
  2. Columns: employee_id, employee_name, and salary
  3. Order by salary descending, then employee_id ascending

Schema

employees
ColumnTypeDescription
employee_idPKINTEGERUnique employee identifier
employee_nameVARCHAR(100)Employee's full name
salaryNUMERIC(12,2)Employee's salary
Tablesemployees
Interviewer

Your question is Fourth Highest Salary in SQL. 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.