how to find the second highest salary from emp table?
Answers were Sorted based on User's Feedback
Answer / anonymous
select Max(salary) from test where salary not in(select Max
(salary) from test);
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / hemant
select salary,empname from employee where
salary=(select max(salary) from employee where
salary<(select max(salary) from employee))
This query will produce all the result whose salary is
second highest.
1. A 20000
2. B 20000
3. C 20000
4. D 20000
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / boring guy
select max(sal) from emp where sal!=(select max(sal) from
emp)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / adithya
select min(sal) from (select distict sal from emp where
rownum<3 order by sal desc)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / pankaj raj patel
select max(salary ) from emp table where sal<(select max
(salary)from emp table)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / kasiraya
SELECT SALARY
FROM
(
SELECT ROW_NUMBER() OVER( ORDER BY SALARY DESC) AS
SL_NO,SALARY
FROM EMP
ORDER BY SALARY DESC
)
WHERE SL_NO=2
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / dinesh rajput
select sal from(select sal from
(select distinct sal from emp order by sal desc)
where rownum<=2 order by sal asc)
where rownum=1;
| Is This Answer Correct ? | 0 Yes | 0 No |
select *from(select *from emp orderby sal desc)where
ronum<=2 minus select *from (select *from emp order by sal
desc ) where rownum<=1;
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / bell
SELECT TOP 1 FieldName FROM (SELECT TOP 2 FieldName FROM
Tabname ORDER BY FieldName DESC) allis ORDER BY FieldName
ASC
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ramu
selectename,sal from (select ename,sal from emp order by sal
desc) where rownum<=5;
| Is This Answer Correct ? | 0 Yes | 0 No |
What is recursive stored procedure?
Does sql*plus have a pl/sql engine?
Why is nosql good?
What is union, minus and interact commands?
How do I add a primary key to a table?
explain advantages of innodb over myisam. : Sql dba
What is t sql used for?
What can I use instead of union in sql?
What is the process of copying data from table a to table b?
what are the differences between require and include, include_once and require_once? : Sql dba
What is an ndf file?
What is the difference between anonymous block and named blocks?
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)