Last answered:

28 Sept 2022

Posted on:

26 Aug 2022

0

Top 10 highest paid employees, not contracts

Hello,

In The Dossier's question, it has been clarified that the result we get was only the top 10 highest paid contracts. It really bothered me create the result that should have been - to get the 10 highest paid employees. That would mean a list of the top salaries but only contains the maximum salary received by each employee. That way, each emp_no would appear once in that list.

After a few digging on the internet, this is what I have came up with:

SELECT *
FROM salaries
WHERE salary IN (SELECT MAX(salary) FROM salaries GROUP BY emp_no)
ORDER BY salary DESC
LIMIT 10;

image.png

I would appreciate your help in checking my work.
Thanks

2 answers ( 0 marked as helpful)
Posted on:

29 Aug 2022

0

Hi,

It seems that I can pull the same result with this simpler command:

SELECT emp_no, MAX(salary) AS salary, from_date, to_date
FROM salaries
GROUP BY emp_no
ORDER BY MAX(salary) DESC
LIMIT 10;
Instructor
Posted on:

28 Sept 2022

0

Hi Carl!
Thanks for reaching out.

Yes, this is a simpler query. Bravo!

Best,
Tsvetelin

Submit an answer