how to find the second highest salary from emp table?
Answers were Sorted based on User's Feedback
Answer / sudhakar tripathi
select Max(salary) "2nd_Heigh_sal" from employees where
(salary < select Max(salary) from employees);
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / ajeshanath
select max(salary) from emp where salary not in
(select max(salary) from emp)
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / amy
select TOP salary from employee where salary in( select TOP 2 salary from employee order by salary desc) order by salary asc
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / praveen kumar.dandu
select a.sal,rank from(select sal,rank() over (order by sal
desc))a where rank=&n
<Here after printing the ranks we can retrieve we can
retreive what ever the rank we want>
| Is This Answer Correct ? | 2 Yes | 4 No |
Answer / sunil
select top 1 * from emp where sal not in (select max(sal)
from emp) order by sal desc
| Is This Answer Correct ? | 1 Yes | 3 No |
Answer / gokul
In MySQL, this query will be easier to find 2nd highest
salary and to fetch all the fields from a table.
select * from emp where sal not in (select max(sal)
from emp) order by sal desc limit 1
| Is This Answer Correct ? | 1 Yes | 3 No |
Answer / lakshmi
select * from (select *,rowcount()over (orderby emp desc)as
rank from emp)b where rank=2
| Is This Answer Correct ? | 0 Yes | 2 No |
Answer / abhijit banik
To get the n-th highest salary from employee table in oracle-10g
--------------------------------------------------------------
select min(salary)
from
(
select rownum rn, salary
from
( select distinct(salary) from employee order by salary desc )
)
where rn<=&n+1
| Is This Answer Correct ? | 1 Yes | 3 No |
Answer / arvind
rameshwari r u idiot dont u know the ans for this simple
que... worst fellow
| Is This Answer Correct ? | 1 Yes | 4 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 u want
| Is This Answer Correct ? | 18 Yes | 22 No |
how can I make a script that can be bi-language (supports english, german)? : Sql dba
What is the difference between sql/pl-sql/embeded sql?
What are the advantages of stored procedure?
what are the advantages a stored procedure? : Sql dba
what is the forward decleration in packages?
Write one update command to update seqno field of a table on the basis of row number.
25.67,-1 Trunc = 20 Round= 30 HOW????
What is sqlcommand?
Explain the components of sql?
What is pragma in sql?
What is difference between stored procedure and trigger?
what is explain plan?, given an example...
Oracle (3253)
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)