Skip to content
Advertisement

How to get employee name with minimum and maximum of salary for second employee name with same salary value in mysql?

I’m having a table odd_empcop in which minimum salary = 2000 and maximum salary =8000 , there are many employees having maximum salary of 8000. I want to get the employee name with minimum salary and maximum salary of second employee.

I’ve applied this code:

getting output like:

But I want to get the output as:

I’VE GOT IT!!!!

Advertisement

Answer

You can use the ROW_NUMBER analytic function to get the details of the employee with the lowest salary and the second employee when ordered by descending salary and then by name:

Which, for the sample data:

Outputs:

emp_name salary
Melinda 8000.00
Gautham 2000.00

MySQL db<>fiddle Oracle db<>fiddle

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