The SQL specification does allow aggregates in the
ORDER BY.  Does mySQL have any plans to add such
functionality (or at least add it to its list of
things it doesn't do)?  The problem with the solution
of ordering by an alias is that I may not necessarily
want the thing I'm ordering by to be in the result
set.  In the example below, I may just want to select
the breed, ordered by minimum age, without showing the
min. age.  Is there a good way in mySQL to make this
work?

Thanks.

> >Why doesn't the following work:
> >
> >mysql> CREATE TABLE dog(id integer, breed char(20),
> >age integer, weight integer)
> >;
> >
> >mysql> SELECT breed, MIN(age)
> >     -> FROM dog
> >     -> GROUP BY breed
> >     -> ORDER BY MIN(age);
> >ERROR 1111: Invalid use of group function
> 
> I don't believe that aggregate functions are legal
> in an ORDER BY clause.
> The solution, as you've found, is to select the
> value you want to order
> by, alias it, and refer to the alias in the ORDER BY
> clause.
> 
> >
> >but this does
> >
> >mysql> SELECT breed, MIN(age) AS minage
> >     -> FROM dog
> >     -> GROUP BY breed
> >     -> ORDER BY minage;
> 
> 
> 
> -- 
> Paul DuBois, Senior Technical Writer
> Madison, Wisconsin, USA
> MySQL AB, www.mysql.com
> 
> Are you MySQL certified? 
> http://www.mysql.com/certification/
> 
> 
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:   
>
http://lists.mysql.com/[EMAIL PROTECTED]
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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

Reply via email to