how to find the second highest salary from emp table?
Answers were Sorted based on User's Feedback
Answer / neil
select * from (select sal,deptno from emp a where
sal in (select distinct(b.sal) from emp b
where a.deptno=b.deptno and rownum<4)
order by deptno,sal desc )
minus
select * from (select sal,deptno from emp a where
sal in (select distinct(b.sal) from emp b
where a.deptno=b.deptno and rownum<3)
order by deptno,sal desc )
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / praveenkumar
SELECT salary FROM EMPtable
WHERE salary NOT IN ( SELECT MAX(salary)
FROM EMPtable)
ORDER BY salary DESC
FETCH FIRST ROW ONLY
---
We have verified and its working
fine.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / arun
select distinct (a.salary) from employees a
where &N = (select count (distinct(b.salary))
from employees b where a.salary <= b.salary);
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / manvar prajesh
select top 1 name,salary from emp where salary<(select
max(salary) from emp)order by salary desc
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / barochia dharmesh
You should use rank query with order by and give where your
search criteria.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / vikas
select * from(select e.*,row_number() over (order by
e.salary desc)rn from Employee e)where rn between 1 and 2
order by rn
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ankit khanijau
Select salary from emp
where MAX(Select salary from emp where salary != MAX(salary))
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / abir dutta
select min(empsal)
from (select * from sal order by empsal desc)
where rownum <=2
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / monika
Select salary from emp order by salary desc LIMIT 1,1;
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / bhoopendra vishwakarma
select salary max(salary) from emp limit1 offset1
| Is This Answer Correct ? | 0 Yes | 0 No |
What is graph sql?
How to execute a stored procedure?
how to include character strings in sql statements? : Sql dba
what is a join? : Sql dba
What is pl sql and why it is used for?
Show the cursor attributes of pl/sql.
What are some emotional triggers?
How to process query result in pl/sql?
What is nested table in pl sql?
I have a CURSOR then why we need BULK COLLECT again?
Can I create table without primary key?
How do I know if I have sql express or standard?
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)