tags:

views:

25

answers:

2

Following is the command to fetch maximum salary form empsalary table in mysql

select max(salary) from empsalary;

but I want to fetch employee who got fourth highest from the list of employee. I don't want to use trigger or function because I know there is direct command to fetch.

+1  A: 

select * from empsalary order by salary desc limit 4

Col. Shrapnel
I want to get only one record of fourth highest.
chetan
A: 

It's essentially as Col. Shrapnel has stated. Select the top 4 records as sorted by salary and then choose the last record. If it's important to do it all in SQL, you could do something like this:

select min(salary) from 
  (select salary from empsalary order by salary desc limit 4) tmp;
dnagirl
Thank for answeringyour solution is correct and working perfect.
chetan