please tell me the query to get details of the employee
having the second largest salary

Answer Posted / rathi

If we had a table named Employee which had a column named
Salary and we had to find the second highest Salary in the
Employee table, the query for the same would be:

SELECT TOP 1 Salary FROM (SELECT TOP 2 Salary FROM Employee
ORDER BY Salary DESC) AS E ORDER BY Salary ASC

The subquery or the inner query would return the top 2 rows
in descending Salary order which would be:
5000
4000
The outer query would then select the top 1 row from the
subquery results in ascending Salary order which would be:
4000

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you do in data exploration

552


How can sql server instances be hidden?

518


Disadvantages of the indexes?

578


Distinguish between commit and rollback?

529


How many servers can we create in a single subscription?

143






difference between Clustered index and non clustered index ?

565


What is difference between Datepart() and Datename() in SqlServer?

707


What is an execution plan? When would you use it?

564


How to write a query with a right outer join in ms sql server?

471


can you instantiate a com object by using t-sql? : Sql server database administration

508


how you can move data or databases between servers and databases in sql server? : Sql server administration

475


What is oltp (online transaction processing)?

573


Please illustrate physical database architecture? : SQL Server Architecture

516


Why we use functions in sql server?

508


What is the definition for sql server 2000?

570