how to get second highest salary in SQL(as/4000
Answers were Sorted based on User's Feedback
Answer / satheeshkumar
Select max(sal) From Employee where sal not in ( Select max
(sal) From Employee)
| Is This Answer Correct ? | 24 Yes | 4 No |
Answer / sachin
select max(sal) from employees
where salary < (select max(sal) from employees);
| Is This Answer Correct ? | 19 Yes | 3 No |
Answer / karunakarreddy.boyapally
SELECT DISTINCT A.SAL FROM EMP A
WHERE &N=(SELECT COUNT(DISTINCT(B.SAL)) FROM EMP B
WHERE A.SAL<B.SAL)
IF SUPPOSE IF U WANT 1 HIGEST SALARY GIVE N=1
IF SUPPOSE IF U WANT 2 HIGEST SALARY GIVE N=2
IF SUPPOSE IF U WANT 3 HIGEST SALARY GIVE N=3
| Is This Answer Correct ? | 10 Yes | 1 No |
Answer / deepak
select max(sal) from emp where sal!=(select max(sal) from emp);
| Is This Answer Correct ? | 12 Yes | 5 No |
Answer / raji_4u
select *
from emp e1
where 2 = ( select count(distinct sal)
from emp e2
where e1.sal <= e2.sal
)
| Is This Answer Correct ? | 8 Yes | 1 No |
Answer / selvaraj v , anna univ coe
SELECT * FROM Employee e
WHERE 2=(SELECT COUNT(DISTINCT Salary) FROM Employee x
WHERE x.Salary >= e.Salary);
| Is This Answer Correct ? | 4 Yes | 0 No |
Answer / sreekanth
SELECT MIN(SAL)
FROM(SELECT DISTINCT SAL FROM EMP
ORDER BY SAL DESC)
WHERE ROWNUM <= :N
where n is the nth highest salary.
In most of the answers,our friends have written 'where
rownum=2',but this never retreives a row.
| Is This Answer Correct ? | 5 Yes | 2 No |
Answer / c srirammulu
select * from emp a where &n=(select count(distinct (sal))
from emp f where a.sal<f.sal)
| Is This Answer Correct ? | 4 Yes | 1 No |
Answer / devi
select sal from (select sal,rank() over(order by sal desc)
as rank from emp) where rank>1 and rank<3
| Is This Answer Correct ? | 4 Yes | 1 No |
What is orm in sql?
What is dml and ddl?
What is pl sql collection?
Why do we need cursor in pl sql?
Where the integrity constrints are stored in Data Dictionary?
Why is sql*loader direct path so fast?
Explain foreign key in sql?
How to use distinct and count in sql query? Explain
How do you retrieve set of records from database server. {Set max records = 100 & use paging where pager page no or records = 10 & after displaying 100 records again connect to database retrieve next 100 }
Is sql better than excel?
what is auto increment? : Sql dba
What is difference between sql and oracle?
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)