Finding the smallest salary difference


You're given the following table showing employees at a company and their respective salaries:

Table: employee_salaries

employee_ID salary
1 80000
2 70000
3 67000
4 85000
5 95000
6 63000
7 58000
8 40000
9 55000

Given the above table, write a SQL query to return the employees with the closest absolute difference in salaries. If there is a tie (e.g. multiple employees have the same salary difference), then show the record with the lower sum of salaries.

You can view/query this table in an interactive SQL fiddle here.


Access restricted

Subscribe to premium account to see the solution.

Get premium now