Friday, November 7, 2008

Select second highest salary from emp table. how to find second highest.

select second highest salary from emp table
 
 select max(sal ) from emp where sal<(select max
(sal)from emp)
 
 select max(sal) from emp where level=2 connect by prior
sal>sal group by level;
 

select the employee details who is having the second highest salary from emp table
 
 select A.* from emp A where 1=(select count(distinct
B.sal) from emp B where B.sal>A.sal)
 
select second highest salary of the employee along with first highest salary from emp table
 
select ename,sal from
 (select ename,sal from emp
 order by sal desc)
 where rownum <=2;
 
Some where i found this solution. it works.
 
keywords: Select second highest salary from emp table. how to find second highest, pl/sql,oracle,mysql,sql server,database,9i,10g,query,doubt,where,blogspot.

No comments: