At 5:52 -0700 10/3/03, Ed Smith wrote:
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]



Reply via email to