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
What do you do in data exploration
How can sql server instances be hidden?
Disadvantages of the indexes?
Distinguish between commit and rollback?
How many servers can we create in a single subscription?
difference between Clustered index and non clustered index ?
What is difference between Datepart() and Datename() in SqlServer?
What is an execution plan? When would you use it?
How to write a query with a right outer join in ms sql server?
can you instantiate a com object by using t-sql? : Sql server database administration
how you can move data or databases between servers and databases in sql server? : Sql server administration
What is oltp (online transaction processing)?
Please illustrate physical database architecture? : SQL Server Architecture
Why we use functions in sql server?
What is the definition for sql server 2000?