Bug #45270 Replacement for Groupwise-Max
Submitted: 2 Jun 2009 17:08 Modified: 13 Jul 2009 9:24
Reporter: Azim Y. Oezdemir Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S4 (Feature request)
Version:5.1 OS:Any
Assigned to: CPU Architecture:Any
Tags: GROUP, groupwise max, order, query

[2 Jun 2009 17:08] Azim Y. Oezdemir
Description:
We all know the "Groupwise Maximum of a Certain Field" method as described in the manual. I think it's time to make a stable solution for this, because the method is too complex when you use it in nested join-queries.

If you google this issue, you'll see that a good solve for this problem is nessecity for the community. With a good solution, users will optain the ability to make very complex group queries. 

How to repeat:
http://dev.mysql.com/doc/refman/5.1/en/example-maximum-column-group-row.html

Suggested fix:
My idea would be expanding the language with the "ordergroup by" option. This is the easiest way in my eyes. 

A example query could be like this:

SELECT *
FROM table1
JOIN table2 ON (table1.id=table2.id)
GROUP BY table2.gender
ORDERGROUP BY table1.birthday DESC
[13 Jul 2009 9:24] Susanne Ebrecht
Many thanks for a reasonable feature request.
[19 Nov 2009 10:21] O T
I suggest the following syntax which returns the corresponding column2 when given:

max( column1 [, column2 ] )