Top three salaries

SQL data engineering interview problem. Difficulty: beginner. Pattern: Sorting. About 8 minutes. Free to practice.

The company wants to know who its top earners are. From the employees table, list the 3 highest-paid employees. Return name, department and salary. Put the highest salary first. If two people earn the same, sort them by name from A to Z. Ignore employees who have no salary.

Requirements

  • Remove rows where salary is NULL before you pick the top ones.
  • Sort by salary from high to low, then by name from A to Z.
  • Return only the first 3 rows after sorting. Use LIMIT 3.

Constraints

  • The table is employees.
  • Return only these 3 columns, in this order: name, department, salary.

Examples

Input: employees name | department | salary Alice Chen | Engineering | 120000 Dan Park | Engineering | 110000 Omar Ali | Sales | 105000 Bob Kumar | Engineering | 95000 Eve Ng | Engineering | 95000 Max Reed | Sales | NULL Output: name | department | salary Alice Chen | Engineering | 120000 Dan Park | Engineering | 110000 Omar Ali | Sales | 105000 Why this passes: LIMIT 3 after sorting by salary descending keeps the three richest non-null rows.

Topics: lakebench, sql, order by, limit, top-n.

More SQL interview questions · All interview problems · Learn data engineering

beginner

Top three salaries

Interview-style drill: Return the three highest-paid employees.

List the top 3 highest-paid employees from `employees`. Columns: `name`, `department`, `salary`. Order by `salary` descending, then `name`. Exclude NULL salaries.