Vivekh
Vivekh

Reputation: 4259

How to list out Top 10 salaries with out using TOP

How can i display Top 10 salaries from a table with out using TOP

Upvotes: 1

Views: 414

Answers (2)

Sachin Shanbhag
Sachin Shanbhag

Reputation: 55489

You can use ROW_NUMBER OVER ( order by ... )

SELECT t.sal from
(
  SELECT  sal, Row_Number() OVER (ORDER BY sal desc) AS rownum
  FROM table
) t 
WHERE  t.rownum <= 10 

Upvotes: 1

Developer
Developer

Reputation: 8636

Try this

SELECT  Salary
from
(
  SELECT  Salary, Row_Number() OVER(ORDER BY SALARY desc) AS 'Salaries'
FROM User2
)#emp 
  WHERE  Salaries <=10 order by salary desc

Upvotes: 2

Related Questions