Write a query to find second highest salary of an employee.
Answers were Sorted based on User's Feedback
Answer / rajasekhar.v
For selecting Nth highest salary...
SQL> select rownum rank,ename,sal from
(select ename,sal from emp order by sal desc)
group by rownum,ename,sal
having rownum = &n;
'n' may be any valid number required..
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / murali
SELECT
MAX(Sal)
FROM
Emp
WHERE
Level=&Levelno
ORDER BY PRIOR Sal>Sal
GROUP BY Level
--Here we have to give &Levelno = 2
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / dilip
select rank,sal from(select rownum rank,distinct(sal) from
emp order by sal desc)
where rank=2;
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / shahid parvez
select max(sal) from Emp where sal < (select max(sal) from
Emp)
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / gyana ranjan behera
select ename,sal.rn from(select ename,sal,rownum rn from(select ename,sal from emp order by sal desc))where rn=2;
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / satheesh
SELECT MAX(SAL) FROM EMP A
WHERE SAL NOT IN(SELECT MAX(SAL) FROM EMP B);
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / manikumar
Select Sal from Emp where Sal in (Select Max(Sal) from Emp)
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / oboyah
SELECT e1.* from ( SELECT last_name, salary,
DENSE_RANK() OVER ( ORDER BY salary DESC) rank
FROM employees) e1 where e1.Rank = 2;
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / om patel
select (distinct(a.sal) from emp e where rownum=&N(select
count(distinct(b.sal)) from emp b where a.sal<=b.sal)
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / akilis.org@hotmail.com
Let us assume that
Table Name:salary
Coloumn Name:maxsal(int)
select * from salary order by maxsal desc limit 1,1;
Is This Answer Correct ? | 0 Yes | 1 No |
how to concatenate two character strings? : Sql dba
what is isam? : Sql dba
What do you understand by pl/sql cursors?
explain about mysql and its features. : Sql dba
how to remove records from table? no name 1 a 2 b 1 a 2 b 3 c
what are date and time functions in mysql? : Sql dba
which will fire first ? Trigger or Constraint
24 Answers i2, IBM,
Does normalization improve performance?
What is trigger in pl sql?
What is bind variable in pl sql?
What is secondary key?
What are the types of join in sql?