sql - What is the efficient query to find out Nth highest salary -
i beginner.. know sql
queries find out 3rd highest salary or nth highest salary. need efficient query.
these queries know.. please suggest other queries instead of these..
this query not efficient per subject teacher
select * employee emp1 (n-1) = ( select count(distinct(emp2.salary)) employee emp2 emp2.salary > emp1.salary );
and query not efficient
select max(salary) employee salary not in (select max(salary) employee );
any hint?
you try this:
select * employee order salary desc limit n,1
and performance pov if had index on salary
column
update: since mysql
tag gone use oracle alternative mentioned mhasan rownum
Comments
Post a Comment