[vox-tech] mysql 4.0 query help

David Hummel dhml at comcast.net
Mon Aug 29 10:33:08 PDT 2005


On Mon, Aug 29, 2005 at 10:13:31AM -0600, timriley wrote:
> 
> I've been following this thread with interest as there are quite
> creative query suggestions. However, I can't help but to see the
> straight forward group-by as what will work.
> 
> select muid, max( total_pct )
> from ca_subgroups
> group by muid;
> 
> I don't think this would return the first associated record.
> What am I missing?

I believe Dylan needs the codename associated with max(total_pct).  If
you add codename to the select in the above query, you will be selecting
the codename from the first row of the rows grouped by muid.  This will
not be the codename associated with max(total_pct) unless total_pct in
the first row of the muid group happens to be the max(total_pct).  So
using Bruce's trick or a sub-select allows the unambiguous selection of
the correct codename value.

-David


More information about the vox-tech mailing list