All tested in MySQL 4.0.x and 4.1.x (MyISAM and InnoDB):

(1) A query with an expression in an ORDER BY clause works well:
SELECT  *
FROM  `table1`
ORDER  BY `col` + 1

(2) A query with an alias of a calculated field in the ORDER BY works also:
SELECT  * , sqrt(  `col1`  )  AS blarg
FROM  `table1`
ORDER  BY blarg

(3) But the combination of an alias in an expression in the ORDER BY:
SELECT  * , sqrt(  `col1`  )  AS blarg
FROM  `table1`
ORDER  BY blarg + 1

results in: #1054 - Unknown column 'blarg' in 'order clause'

In the manual there is stuff about aliases in WHERE clauses, in GROUP BY,
but the use in ORDER BY is a bit of a mystery to me. I don't see why (2)
would work and (3) not!?

If necessary you can use the HAVING clause to use expressions that aren't
allowed in WHERE, but there is no such thing as a post-having-order-by
clause ;-)

Regards, Jigal


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

Reply via email to