SQLSQL
#42

Department Top Three Salaries in SQL

HardAmazon
Interview Question #42
Asked at Amazon

Given `employee` (id, name, salary, departmentId) and `department` (id, name), write a query to find employees who earn a salary in the top 3 unique salaries of their department.

Input Table: employee & department
6 rows preview
emp_namesalarydepartment_name
Joe85000IT
Henry80000IT
Sam60000IT
Max90000IT
Janet69000Sales
Randy85000Sales
Expected Output Structure5 rows
DepartmentEmployeeSalary
ITMax90000
ITJoe85000
ITHenry80000
SalesRandy85000
SalesJanet69000
Interview Context

Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.

SQLPostgreSQL 15
Ready to execute

Click "Run Query" or press Ctrl + Enter to test your query.

Output will be verified against the test dataset.

Chat with us