Unix Technical Forum

Extracting top five only for each group

This is a discussion on Extracting top five only for each group within the MySQL forums, part of the Database Server Software category; --> A have a table, a classic student test result table that contains StudentID, TestID and Score. For any student ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 06:20 AM
andrew_d_may@hotmail.com
 
Posts: n/a
Default Extracting top five only for each group

A have a table, a classic student test result table that contains
StudentID, TestID and Score. For any student there can be any number
of scores, including zero, for any given test. For a given student I
want to extract the scores for each test and am using:

Select * from Results where StudentId=x order by TestID, Score;

This returns all the results for a given student and works fine. What
I really want to do though is to only return the top five scores for
_each_ test.

I am sure this is easy and am guessing that this requires some form of
select from (select from ...) syntax but cannot work out what.

Could some kind soul please point me in the right direction?

Andrew
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 06:20 AM
Captain Paralytic
 
Posts: n/a
Default Re: Extracting top five only for each group

On 18 Apr, 09:02, "andrew_d_...@hotmail.com"
<andrew_d_...@hotmail.com> wrote:
> A have a table, a classic student test result table that contains
> StudentID, TestID and Score. For any student there can be any number
> of scores, including zero, for any given test. For a given student I
> want to extract the scores for each test and am using:
>
> Select * from Results where StudentId=x order by TestID, Score;
>
> This returns all the results for a given student and works fine. What
> I really want to do though is to only return the top five scores for
> _each_ test.
>
> I am sure this is easy and am guessing that this requires some form of
> select from (select from ...) syntax but cannot work out what.
>
> Could some kind soul please point me in the right direction?
>
> Andrew


There are just SO MANY answers around to this already!
I just Googled "mysql top n group" and got a massive list.
Here's a link to the first one:

http://thenoyes.com/littlenoise/?p=36
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 06:20 AM
Captain Paralytic
 
Posts: n/a
Default Re: Extracting top five only for each group

On 18 Apr, 09:02, "andrew_d_...@hotmail.com"
<andrew_d_...@hotmail.com> wrote:
> A have a table, a classic student test result table that contains
> StudentID, TestID and Score. For any student there can be any number
> of scores, including zero, for any given test. For a given student I
> want to extract the scores for each test and am using:
>
> Select * from Results where StudentId=x order by TestID, Score;
>
> This returns all the results for a given student and works fine. What
> I really want to do though is to only return the top five scores for
> _each_ test.
>
> I am sure this is easy and am guessing that this requires some form of
> select from (select from ...) syntax but cannot work out what.
>
> Could some kind soul please point me in the right direction?
>
> Andrew


There are just SO MANY answers around to this already!
I just Googled "mysql top n group" and got a massive list.
Here's a link to the first one:

http://thenoyes.com/littlenoise/?p=36
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-21-2008, 05:47 AM
andrew_d_may@hotmail.com
 
Posts: n/a
Default Re: Extracting top five only for each group

On 18 Apr, 16:27, Captain Paralytic <paul_laut...@yahoo.com> wrote:

> There are just SO MANY answers around to this already!
> I just Googled "mysql top n group" and got a massive list.
> Here's a link to the first one:
>
> http://thenoyes.com/littlenoise/?p=36


Thank you. That was the pointer that I needed. I was missing the
'group' in the search terms.

Andrew

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:36 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com