Back To Normal

Subscribe To Our E-Mail Newsletter

Thursday, June 17, 2010

Find out nth Highest salary from Emp table


Couch ModePrint It

SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal); Output : n=2 , it will display 2nd highest salary from table. Otherwise We can use rank statement to find second largest:
select column1
from
(
select column1 rank() over (order by column1 desc) rank from
(select distinct(column1) from table1)
)
where rank 2;

Simple Solution:
-----------------
 Select max(Column1) from table1 where Column1 < (select max(Column1) from table1)

Click Here For Smileys :D
:D
:)
:[
;)
:D
:O
(6)
(A)
:'(
:|
:o)
8)
(K)
(M)

No comments:

560 Free Online Courses

Top 200 universities launched 500 free online courses.  Please find the list here .