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 are different types of replication in sql server?
How do you test your database? : sql server database administration
how can you attach more than 20 ldf files in sql server
How to encrypt Strored Procedure in SQL SERVER?
What is a fan-out query in SQL Azure?
What are sql dirty pages?
What is the simplest way to create a new database in ms sql server?
Explain “not null constraint” in sql server?
What is a sql join?
Explain differentiate between a having clause and a where clause?
What does it mean to manipulate data?
What is 2nf normalization?
What is data modification?
can an order by clause be used in a creation of a view?
Please explain that what are the basic functions for master, msdb, model, tempdb and resource databases? : SQL Server Architecture