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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select TOP n of each Group
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

94 Posts

Posted - 09/08/2013 :  06:59:11  Show Profile  Reply with Quote
Hello I'm trying to find the most effective way to get the top N of each group in a group by

I've already try the ROW_NUMBER() OVER PARTITION Method but it is still slow

I've also checked the CROSS APPLY Method not really more efficient

Bu t My group is very simple and limited to one column
So Now I'm on the way to use a stored procedure make a loop of TOP n for each distinct element of my column

Any comment or other Idea ?

Thanks for any help

Bustaz Kool
Flowing Fount of Yak Knowledge

1834 Posts

Posted - 09/09/2013 :  17:16:02  Show Profile  Reply with Quote
The ROW_NUMBER() OVER PARTITION approach seems to be the way to go. Let us see your code and perhaps someone can determine why it is running slow. Also, can you quantify what "slow" actually means?

The cure for anything is salt water -- sweat, tears, or the sea. -Isak Dinesen
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000