List:General Discussion« Previous MessageNext Message »
From:Roger Baklund Date:January 28 2004 3:45pm
Subject:Re: Group By Problem
View as plain text  
* Lightware Software
> Say I have the following table (TBL):
>
> KEY GRP VAL
>  1 A 2
>  2 A 3
>  3 A 1
>
>  4 B 2
>  5 B 1
>  6 B 3
>
> "select KEY, max(VAL) from TBL group by GRP" gives:
>
> KEY max(VAL)
> ------------
>  1 3
>  4 3
>
> the desired result though is:
>
> KEY max(VAL)
> ------------
>  2 3
>  6 3
>
> any ideas on how to achieve this ?

There is a special page in the manual for this problem, one of my favorite
sql hacks is the MAX-CONCAT trick:

<URL: http://www.mysql.com/doc/en/example-Maximum-column-group-row.html >

--
Roger

Thread
Group By ProblemLightware Software28 Jan
  • Re: Group By ProblemRoger Baklund28 Jan
    • UNION equivilent required for 3.23.37Andy Hall28 Jan