Skip to content
Advertisement

List the Employee details for any Employee that has the highest salary for their species expertise

The question is:

List the Employee details for any Employee that has the highest salary for their species expertise

It is to be solved using Employee and V1 table (v1 is a view created using employee table)

https://imgur.com/a/chIFHmT : first table is employee and second table is V1

Using the query below gives me all the right output beside it matches Tiger salary of 75000 while it should ONLY be showing Tiger Salary of 90000. (its showing both)

Expected Result:

Current query:

Actual Result I get When I run Query above:

Advertisement

Answer

You are looking to pull out the employee that has the highest salary for each species. You could achieve this with just a NOT EXISTS condition and a correlated subquery:

If there are top ties (ie if more than one employee have the same, maximum salary for a given species), they will all be displayed.

NB: I don’t really see the point using the v1 view, so I did not.

Starting MySQL 8.0, window functions come into play, and this can be solved in a more efficient manner:


If you really want to use v1, then you would need to change you JOIN conditions. Consider:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement