List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:March 26 2003 10:18pm
Subject:Re: Alias Error in a select statement
View as plain text  
>rafarife@stripped writes:
>>  Description:
>>       Hello,
>>
>>    
>>     When I run the following query:
>>
>>     Select Can as MiCantidad, MiCantidad * 2 from Stocks limit 10
>>
>>     I get the following error:
>>
>>     'The column 'MiCantidad' in field list is unknown'
>> 
>>     So, Can I reference to a column by its alias in a
>>     select statement?   
>>
>>
>>     Thanks in advance,
>>     Rafa
>>
>>  How-To-Repeat:
>>     Select Can as MiCantidad, MiCantidad * 2 from stocks limit 10
>
>Hi!
>
>This is not  a bug.
>
>You can not reference an alias in the select list.
>
>You can do it freely in WHERE, ON , GROUP BY and other clauses.

Not quite...

Not in a WHERE clause.  Well, table aliases, yes; column aliases, no.

>
>--
>    __  ___     ___ ____  __
>   /  |/  /_ __/ __/ __ \/ /    Mr. Sinisa Milivojevic <sinisa@stripped>
>  / /|_/ / // /\ \/ /_/ / /__   MySQL AB, Fulltime Developer
>/_/  /_/\_, /___/\___\_\___/   Larnaca, Cyprus
>        <___/   www.mysql.com

Thread