how to find the second highest salary from emp table?
Answers were Sorted based on User's Feedback
Answer / sheela
Select top 2 sal from (select sal from emp order by sal
desc)
| Is This Answer Correct ? | 0 Yes | 0 No |
query:
======
select e.name,e.salary from emp e where &n =(select
count(distinct ee.salary) from emp ee where e.salary<=e.salary)
after run enter n value:
if 2 enter second max salary will come
if 3 enter third max salary will come.
otherwise, we can write below
select e.name,e.salary from emp e where 2 =(select
count(distinct ee.salary) from emp ee where e.salary<=e.salary)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / nitin
SQL> select emp_sal from (select emp_sal from nitin order
by emp_sal desc) group by rownum,emp_sal
having rownum=2;
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / rahul thakur
select top 1 salary from emp where id not in (select top1 id from emp order by salary desc)order by salary desc.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / mastan
select name,salary from (select salary from emp order by
salary desc)where rownum<2
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / jyotiprokash
Select * from emp e1 where 1=(select count(distinct sal) from emp e2 where e1.salary<e2.salary)
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / raja
first find third maximum
then it ll be very easy to find second maximum.. :)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / em rao
select max(sal)
from emp
where sal<
(select max(sal)
from emp;)
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / kameshwar shukla(a.i.e.t l.k.o
select max(sal) from emp where sal < (select max(sal) from
emp)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / khushbu
select max(salary) from emp where salary not in (select
max(salary) from emp)
| Is This Answer Correct ? | 0 Yes | 0 No |
What is rank function in sql?
Explain the usage of WHERE CURRENT OF clause in cursors ?
how to convert numeric values to character strings? : Sql dba
What are the topics in pl sql?
Does sql profiler affect performance?
how does a local variable is defined using t-sql? : Transact sql
What is the non-clustered index in sql?
how to convert character strings to dates? : Sql dba
What is ttitle and btitle?
Can we use distinct and group by together?
What will be the output for the below Query Select 'High' from dual where null = null;
Can we want to pass a parameter payroll_id to this external pl/sql function, how do we do it?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)