Connecting Tech Pros Worldwide Forums | Help | Site Map

SQL : nth highest salary from emp table

Newbie
 
Join Date: Aug 2008
Posts: 1
#1: Aug 28 '08
select distinct (a.salary) from employees a
where &N = (select count (distinct(b.salary))
from employees b where a.salary <= b.salary);

Pls any one explain how the query works, logic behind it.

Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Aug 28 '08

re: SQL : nth highest salary from emp table


Which part don't you understand? Split it up and try to understand each part separately first.
Reply