Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Third Highest Value in SQL

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

Your question is Third Highest Value in SQL. Start with the requirements and the two tables 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

Mediaagility needs a salary analysis for active employees assigned to recognized departments. Write a PostgreSQL query that returns every employee earning the third-highest distinct salary in that population.

Requirements

  1. Consider only employees whose employment_status is active and whose salary is not NULL.
  2. Include only employees with a matching department record.
  3. Rank distinct salary values from highest to lowest, so employees tied at the same salary share a rank.
  4. Return the employee name, department name, salary, and results ordered by employee name.

Schema

employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(100)Employee full name
department_idINTDepartment assigned to the employee
salaryNUMERIC(10,2)Annual employee salary
employment_statusVARCHAR(20)Current employment status
departments
ColumnTypeDescription
department_idPKINTUnique department identifier
department_nameVARCHAR(100)Department name
Tablesemployeesdepartments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results