Paul wrote:
> I am curious what is a particular reason that aliased columns in a query not 
> visible to sub-queries?

Because the SQL standard says so.

> Of course it is possible to duplicate expression in sub-query ...
> But this would not be as efficient as to access result of already evaluated 
> expression.

An alias refers not to an expression's value but to the expression
itself, so it would not be any more efficient.  (SQLite's optimizer
typically is not smart enough to detect and remove the duplication.)


As a workaround, you have to move the expression into a subquery in
the FROM clause:

SELECT super_id,
       (SELECT qux FROM baz WHERE id = super_id)
FROM (SELECT id as super_id FROM foo);


Regards,
Clemens

Reply via email to