Hi Yves,

You can use a having clause to work with groups:

select grp, max(id) as maxid
from tbl
group by grp
having maxid = max(id)

Regards,

Peter Sap

----- Original Message -----
From: "Yves Goergen" <[EMAIL PROTECTED]>
To: "List: MySQL" <[EMAIL PROTECTED]>
Sent: Thursday, November 20, 2003 11:28 PM
Subject: How to 'customize' GROUP BY?


> Hi again...
> yet another question to this list that maybe someone can easily answer
me...
>
> When I do a GROUP BY on a column of my query, I'll get one random row from
> the entire group. But how can I tell MySQL to, i.e., give me the row with
> the highest value of another column or so? I mean something like
>
>     SELECT id, grp FROM tbl GROUP BY grp ORDER BY id
>
> but with the ORDER BY relating to the GROUP... I don't know how to express
> this in SQL since it doesn't seem to be possible?
>
> --
> Yves Goergen
> [EMAIL PROTECTED]
> Please don't CC me (causes double mails)
>


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to