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 2005 Forums
 Other SQL Server Topics (2005)
 Top 10 select

Author  Topic 

Foxy
Starting Member

5 Posts

Posted - 2010-11-15 : 07:10:41
Hi I need to write a top 10 query that selects the top 10 results for different processes in one query and I am really struggling can someone please help!!!

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-15 : 07:36:53
select top 10 ... from table order by somecol

Madhivanan

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

Foxy
Starting Member

5 Posts

Posted - 2010-11-15 : 07:43:43
Select ProcessValue
from
Select top10 processValue where process = '1' oder by processValue
select top10 processValue where process = '2' order by processValue

where
...

I need something like this
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-15 : 07:47:32
quote:
Originally posted by Foxy

Select ProcessValue
from
Select top10 processValue where process = '1' oder by processValue
select top10 processValue where process = '2' order by processValue

where
...

I need something like this


Can you post the full code which is used?

Madhivanan

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

Foxy
Starting Member

5 Posts

Posted - 2010-11-15 : 07:54:52
..
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-15 : 08:00:57
Ok. What is the problem with your query?

Madhivanan

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

Foxy
Starting Member

5 Posts

Posted - 2010-11-15 : 08:10:28
..
Go to Top of Page

michael.appleton
Posting Yak Master

160 Posts

Posted - 2010-11-15 : 09:16:10
Use row_number to select top n from more than one group. Have a look here http://www.kodyaz.com/articles/top-n-random-rows-foreach-category-or-group.aspx
Go to Top of Page

Foxy
Starting Member

5 Posts

Posted - 2010-11-15 : 09:19:58
quote:
Originally posted by michael.appleton

Use row_number to select top n from more than one group. Have a look here http://www.kodyaz.com/articles/top-n-random-rows-foreach-category-or-group.aspx



thanks this look like what I am looking for
Go to Top of Page
   

- Advertisement -