Subject Re: [firebird-support] Why field alias can not be used in where clause?
Author Daniel Rail

At November 25, 2005, 4:20 AM, Jonathan Neve wrote:

> Glebas wrote:

>>Using FB1.52 on Windows:
>>select tbl.fld as alias from tbl where alias is null
>>complains about 'alias' in 'where' clause:
>>'Column does not belong to referenced table'
> FB 1.5.2 doesn't support using aliases in the where clause.

>>in firebird 2 release notes I found that now field aliases can be used
>>in 'order by' and 'group by'. But why 'where' clause is so special?
> I agree, it would be nice. Perhaps in a future version.

> I suggested that once, but I was told that it would be difficult because
> (IIRC) the where clause is evaluated before the fields in the select.

Also, an alias might point to an aggregate function(i.e.: SUM), which
can only be evaluated after the WHERE clause. So essentially, not all
the aliases in the select result set could be used in the WHERE
clause, and that would lead to confusion. But, the HAVING clause is
meant to be used against the result set, which if it doesn't support
aliases in FB2, then that could be asked as a feature request for FB3.
I haven't tested it in FB2, but I do know that it doesn't work in FB
1.5. And, at the moment, the HAVING clause as to be used with a GROUP
BY clause.

Best regards,
Daniel Rail
Senior Software Developer
ACCRA Consultants Inc. (
ACCRA Med Software Inc. (