Given an employee table, how would you find out the second
highest salary?
Answers were Sorted based on User's Feedback
Answer / sowjanya
Select * from emp where sal=(select Max(sal) from emp where
sal<(select Max(Sal) from emp)
| Is This Answer Correct ? | 7 Yes | 0 No |
Answer / trived
select * from emp
where n-1 = (select count(*) from emp e
where emp.salary<e.salary)
in place of n-1 you can keep zero for first hight salary
and 1 for second hightest salary.....etc
| Is This Answer Correct ? | 9 Yes | 3 No |
Answer / rony sunny
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP 2 salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
| Is This Answer Correct ? | 5 Yes | 1 No |
Answer / ravikumar
select ename,esal from
(select ename,esal from hsal
order by esal desc)
where rownum <=2
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / balindra sahani
select max(sal) from emp
where sal not in (select max(sal) from emp )
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / karna
select top 1 a.salary,* from emp a
where a.salary not in(select top (n-1) b.salary from emp b)
here n is the Nth values:if you want secong highest: keep n
as 2 so the query will become
select top 1 a.salary,* from emp a
where a.salary not in(select top 1 b.salary from emp b)
| Is This Answer Correct ? | 3 Yes | 2 No |
Answer / balindra sahani
select max(sal) from emp
where sal not in (select max(sal) from emp order by sal desc )
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / mithilesh mishra
Select Max(sal) from emp where sal not in (select max(sal)
from emp)
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / vivek mohan singh
select salary from tablename order by salary desc limit 1,1;
| Is This Answer Correct ? | 2 Yes | 3 No |
What is normalization? Explain different levels of normalization?
8 Answers CG-VAK, Choice Solutions, College School Exams Tests, IBM, Wipro,
What you can do to remove data from the cache and query plans from memory for testing the performance of a query repeatedly?
How to combine two function together?
Explain about relational operator join?
What are the main phases of database development?
Write short notes on manual refreshes.
What is dbms and its application?
You are testing the performance of a query the first time you run the query, the performance is slow. the second time you run the query, the performance is fast. why is this?
How to create an external table.
What are the key features of dbms?
To convert IDMS to DB2, how to deal with IDMS occurs and redefined clause?
In which table collections errors are stored.
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)