fetch fourth maximum record from the table field
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.
select * from empsalary order by salary desc limit 4
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;
精彩评论