View Single Post
  #8 (permalink)  
Old December 18th, 2003, 05:32 AM
owain owain is offline
Friend of Wrox
 
Join Date: Jun 2003
Location: Cardiff, , United Kingdom.
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Another way of doing it would be to use a derived table. The inner query selects the top 3 salaries and the outer query selects the lowest salary from this result set.
Code:
  SELECT TOP 1 [Name], Sal
    FROM (SELECT TOP 3 [Name], Sal
            FROM employee
        ORDER BY Sal DESC) AS E2
ORDER BY Sal
This will return only one row, and that row will be the third row in the table if you had selected it by returning all the rows, ordered by salary and moved to the third row. Jeff's query is probably closer to what you want but it shows that there are usually more than one way do achieving what you want in SQL.

Regards
Owain Williams