Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Top N Highest Paid
00:00
5 left

SQL Top N Highest Paid

EasySQL · PostgreSQL

Problem

Write a SQL query to retrieve the top 5 highest-paid employees from a table.

Assume the table is named employees. Return the highest salaries first, placing tied employees in ascending employee_id order.

Output

  1. Exactly five rows with employee_id, employee_name, and salary
  2. Rows ordered by salary descending, then employee_id ascending for ties
  3. Employees with NULL salaries are not included in the top five

Schema

employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(100)Employee full name
salaryDECIMAL(10,2)Annual employee salary
departmentVARCHAR(50)Employee department
hire_dateDATEEmployee hire date
Tablesemployees
Interviewer

Your question is SQL Top N Highest Paid. 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.