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 are the different kinds of ssrs reports?

170


What options are available to audit login activity? : sql server security

647


How many types of attribute relationships are there? : sql server analysis services, ssas

596


Write a query for primary key constraint with identity key word?

587


How to disable a login name in ms sql server?

605






What are the dmvs?

579


Explain about protocol layer present in SQL server?

617


How to find the service pack installed? : sql server database administration

562


How many types of schemas are there?

539


How do you rebuild an identity column?

563


As a general practice, it is recommended to have dbo be the owner of all database objects however, in your database you find number of tables owned by a user other than dbo, how could you fix this?

630


Can you pass expressions to function parameters?

552


What are the differences between lost updates and uncommitted dependencies?

555


Find columns used in stored procedure?

538


How to connect to a sql server using odbc_connect()?

629