Hi. On Wed, May 29, 2002 at 02:36:11AM +0200, [EMAIL PROTECTED] wrote: > It seems I cannot use an alias in WHERE clause, but I can use it in ORDER > BY.
Correct. > An examples: > > this doesnt work > SELECT field1 AS ABC, field2 AS XXX, field3 AS QQQ FROM mytable WHERE ABC = > 'abc' ORDER BY ABC > > this works > SELECT field1 AS ABC, field2 AS XXX, field3 AS QQQ FROM mytable WHERE > field1 = 'abc' ORDER BY ABC > > Why I cannot use the alias 'ABC' in WHERE clause and I can use it in ORDER > BY clause? Because the WHERE clause is applied before the SELECT clause evaluated and therefore before any aliases are evaluated/known. So they are not known in the WHERE clause. The ORDER BY comes afterwards, therefore there is no error using aliases in there. You could use the HAVING clause, which is applied after the SELECT clause, but no indexes will be used on expressions in there. That is how the SQL standard defines it. Bye, Benjamin. -- [EMAIL PROTECTED] --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php