lto:[EMAIL PROTECTED]
Sent: Wednesday, April 21, 2004 1:46 PM
To: Chris
Cc: [EMAIL PROTECTED]
Subject: Re: Confused by max and group by
This seems bizarre. Although I am the SQL neophyte and it is perhaps not
my right to whine about the mysteries of SQL, but this seem very surprising
and nonint
The problem you are running into is that you are getting the max of one
field and grouping by another. But then you want to get a third field
that changes within the grouping.
Perhaps this might work
SELECT myindex, myval, mycat
FROM `mytest`
GROUP BY mycat
ORDER BY myindex DESC;
I think what is happening is that you are getting the max value for one
field, but the "first" values for the other fields. Try ordering you
group by:
SELECT max(myindex), myval, mycat
FROM `mytest`
GROUP BY mycat DESC;
On Apr 21, 2004, at 1:35 PM, Noah Spurrier wrote:
I'm having trouble with "
You aren't making any mistakes, it's just not possible to do. You can't rely
on which row MySQL will return when using a GROUP BY clause.
The standard method would be to do something like this:
CREATE TEMPORARY TABLE mytemptable
SELECT max(myindex) as myindex, mycat
FROM `mytest`