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
 General SQL Server Forums
 New to SQL Server Programming
 Help with Group By, Order By, LIMIT

Author  Topic 

pgb205
Starting Member

2 Posts

Posted - 2008-11-25 : 14:15:04
I want to retrieve data from a single table and then group it by column1, then subgroup it by column2 , then sort it within each one of those groups and finally display upto 10 results from each one of those sorted groups. Can someone please help with pseudocode as I'm having trouble making this work. Right now it looks like
Select * from table_name where some_condition=TRUE group by column1, column2 order by column3. I'm not even sure how to work the limit clause into this statement as this causes only 10 values to be retrieved overall not 10 from every group.

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-11-25 : 14:40:28
This is a forum for question about Microsoft SQL Server.

Are you running MySQL? If so, you should post your questions on a forum where they handle MySQL questions, like http://www.dbforums.com



CODO ERGO SUM
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-11-25 : 14:40:43
See this:
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/09/12/return-top-n-rows.aspx
Go to Top of Page
   

- Advertisement -