Extracting top five only for each group

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


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2008
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
Reply With Quote
  #2 (permalink)  
Old 04-18-2008
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
Reply With Quote
  #3 (permalink)  
Old 04-18-2008
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
Reply With Quote
  #4 (permalink)  
Old 04-21-2008
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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:13 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0