Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL Query

Author  Topic 

anubhav
Starting Member

1 Post

Posted - 2006-06-01 : 05:20:33
Can any one suggest me a query to find n highest values of a column from a table, I mean all the n not the nth or Highest.

for example: to find top ten salaries from an employee table.

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-06-01 : 05:23:11
Did you mean

Select Top n From Table

??

If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-01 : 05:24:58
Always use ORDER BY with TOP

SELECT TOP 10 SALARY FROM EMPLOYEE ORDER BY SALARY DESC



KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-01 : 06:27:56
If you want it generalise then

Declare @top int
Set @top=10

Set RowCount @top
SELECT SALARY FROM EMPLOYEE ORDER BY SALARY DESC
Set RowCount 0

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -