Unix Technical Forum

Help with simple mysql query please

This is a discussion on Help with simple mysql query please within the MySQL forums, part of the Database Server Software category; --> Hello, I have a mysql table called Points with like : Name | Grade | Points Bill | 1 ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 03:49 PM
J
 
Posts: n/a
Default Help with simple mysql query please

Hello,
I have a mysql table called Points with like :

Name | Grade | Points
Bill | 1 | 5
Tom | 1 | 10
Fred | 2 | 7
Amy | 2 | 3
Ally | 3 | 10
Zoe | 3 | 11
and so on......

I need a query that will return the top point leader by grade.
1 - Tom - 10
2 - Fred - 7
3 - Zoe = 11

Can someone tell me how to do this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 03:49 PM
Erick T. Barkhuis
 
Posts: n/a
Default Re: Help with simple mysql query please

J:
> Hello,
> I have a mysql table called Points with like :
>
> Name | Grade | Points
> Bill | 1 | 5
> Tom | 1 | 10
> Fred | 2 | 7
> Amy | 2 | 3
> Ally | 3 | 10
> Zoe | 3 | 11
> and so on......
>
> I need a query that will return the top point leader by grade.
> 1 - Tom - 10
> 2 - Fred - 7
> 3 - Zoe = 11
>
> Can someone tell me how to do this?


What's your requirement when multiple 'name' end up in first place for a
grade?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 03:49 PM
Captain Paralytic
 
Posts: n/a
Default Re: Help with simple mysql query please

On 29 Feb, 00:42, J <japhyrider2...@yahoo.com> wrote:
> Hello,
> I have a mysql table called Points with like :
>
> Name | Grade | Points
> Bill | 1 | 5
> Tom | 1 | 10
> Fred | 2 | 7
> Amy | 2 | 3
> Ally | 3 | 10
> Zoe | 3 | 11
> and so on......
>
> I need a query that will return the top point leader by grade.
> 1 - Tom - 10
> 2 - Fred - 7
> 3 - Zoe = 11
>
> Can someone tell me how to do this?


You are looking for the strawberry query.
http://dev.mysql.com/doc/refman/5.0/...group-row.html
Look at the LEFT JOIN example (NOT the subselect)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-01-2008, 03:49 PM
J
 
Posts: n/a
Default Re: Help with simple mysql query please

On Feb 29, 1:23*am, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 29 Feb, 00:42, J <japhyrider2...@yahoo.com> wrote:
>
>
>
>
>
> > Hello,
> > I have a mysql table called Points with like :

>
> > Name | Grade | Points
> > Bill * * | 1 * * * *| 5
> > Tom * | 1 * * * *| 10
> > Fred * | 2 * * * *| 7
> > Amy *| 2 * * * *| 3
> > Ally * | 3 * * * *| 10
> > Zoe * | 3 * * * *| 11
> > and so on......

>
> > I need a query that will return the top point leader by grade.
> > 1 - Tom - 10
> > 2 - Fred - 7
> > 3 - Zoe = 11

>
> > Can someone tell me how to do this?

>
> You are looking for the strawberry query.http://dev.mysql.com/doc/refman/5..0...column-group-r...
> Look at the LEFT JOIN example (NOT the subselect)- Hide quoted text -
>
> - Show quoted text -


Thanks for the replies. Thats what I was looking for!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-01-2008, 03:49 PM
Joe Beasley
 
Posts: n/a
Default Re: Help with simple mysql query please

Captain Paralytic wrote:
> On 29 Feb, 00:42, J <japhyrider2...@yahoo.com> wrote:
>> Hello,
>> I have a mysql table called Points with like :
>>
>> Name | Grade | Points
>> Bill | 1 | 5
>> Tom | 1 | 10
>> Fred | 2 | 7
>> Amy | 2 | 3
>> Ally | 3 | 10
>> Zoe | 3 | 11
>> and so on......
>>
>> I need a query that will return the top point leader by grade.
>> 1 - Tom - 10
>> 2 - Fred - 7
>> 3 - Zoe = 11
>>
>> Can someone tell me how to do this?

>
> You are looking for the strawberry query.
> http://dev.mysql.com/doc/refman/5.0/...group-row.html
> Look at the LEFT JOIN example (NOT the subselect)

Using the above link I used ...

select Name,Grade,points from Test1 t1
where points = (select max(points) from Test1 t2
where t1.Grade = t2.Grade)
order by Grade
;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-01-2008, 03:49 PM
Paul Lautman
 
Posts: n/a
Default Re: Help with simple mysql query please

Joe Beasley wrote:
> Captain Paralytic wrote:
>> On 29 Feb, 00:42, J <japhyrider2...@yahoo.com> wrote:
>>> Hello,
>>> I have a mysql table called Points with like :
>>>
>>> Name | Grade | Points
>>> Bill | 1 | 5
>>> Tom | 1 | 10
>>> Fred | 2 | 7
>>> Amy | 2 | 3
>>> Ally | 3 | 10
>>> Zoe | 3 | 11
>>> and so on......
>>>
>>> I need a query that will return the top point leader by grade.
>>> 1 - Tom - 10
>>> 2 - Fred - 7
>>> 3 - Zoe = 11
>>>
>>> Can someone tell me how to do this?

>>
>> You are looking for the strawberry query.
>> http://dev.mysql.com/doc/refman/5.0/...group-row.html
>> Look at the LEFT JOIN example (NOT the subselect)

> Using the above link I used ...
>
> select Name,Grade,points from Test1 t1
> where points = (select max(points) from Test1 t2
> where t1.Grade = t2.Grade)
> order by Grade
> ;


Wrong one!!!!

The section itself (as did I) points out that the correct one to use is the
LEFT JOIN. It is far more efficient!


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 04:52 PM.


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