[thelist] MySQL Grouping problem

Matt Warden mwarden at gmail.com
Mon Apr 11 15:01:01 CDT 2005


Richard,

On Apr 11, 2005 3:41 PM, Richard Livsey <richard at livsey.org> wrote:
> >Try MIN(distance) in the select clause
> >
> >
> That gets the min distance ok, but doesnt get the rest of the fields
> correctly still.
> 
> SELECT * , MIN( distance ) AS minDist
> FROM places
> GROUP BY TYPE
> ORDER BY minDist ASC
> 
> IE:
> 
> +------+---------+---------+---------+--------+
> | id   | name    | distance| type    | minDist|
> +------+---------+---------+---------+--------+
> | 2    | gregs   | 150     | bakery  | 150    |
> +------+---------+---------+---------+--------+
> | 1    | barclays| 400     | bank    | 200    |
> +------+---------+---------+---------+--------+

I really do not understand what you are trying to do. I'm surprised,
actually, that your query is not throwing errors. Typically, the
selected columns either need to be in the GROUP BY clause or have an
aggregate function operating on it.

Could you post more than 2 rows of what you are desiring, so we can
get a better idea of the ordering you want and how that relates to
whatever you are trying to do with the grouping?

I almost suspect that you are simply trying to order by distance and
then by type (or the other way around). But, I can't tell.

Thanks,

-- 
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.


More information about the thelist mailing list