need help with group by ~

Codes here !

Moderators: egami, macek, gesf

Post Reply
unisabilly
New php-forum User
New php-forum User
Posts: 19
Joined: Wed Aug 17, 2005 6:00 am

Tue Jun 27, 2006 1:30 am

suppose I have a table as follow :

Code: Select all

name    subject    mark
--------------------------------------
Michael   Math     60
Michael   History   68
Ellen         Math     72
Ellen         English    58
Ellen         Science   43
Jason      Biology    42
Jason     English     67
Jason      Accounting   73
Jason     Math      68
Julia       History    76
Julia       Science     54
Julia       Biology      77
how can I select the name and subject of the best mark for every subject ?

Thanx in advance for help ~

User avatar
Redcircle
Moderator
Moderator
Posts: 826
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Tue Jun 27, 2006 9:04 pm

Code: Select all

select * from table group by subject order by mark desc

unisabilly
New php-forum User
New php-forum User
Posts: 19
Joined: Wed Aug 17, 2005 6:00 am

Wed Jun 28, 2006 2:05 am

Redcircle wrote:

Code: Select all

select * from table group by subject order by mark desc
.......... somehow the result is not correct ~

Post Reply