On Mon, Feb 8, 2016 at 3:38 AM, Paul <devgs at ukr.net> wrote: > I see, thank you for pointing out. > > I wanted to use it on table with conditional relations with 3 different child > tables. > Though I could use a trick and fit data selection into one query, efficiently. > Alas I am forced to stick to 2 queries. >
Might still be able to collapse it into one CTE query.... but I don't know what the other part is to demo that... https://www.sqlite.org/lang_with.html > Thank you! > > 8 February 2016, 12:08:26, by "Clemens Ladisch" <clemens at ladisch.de>: > >> 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 >> _______________________________________________ >> sqlite-users mailing list >> sqlite-users at mailinglists.sqlite.org >> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users > > > _______________________________________________ > sqlite-users mailing list > sqlite-users at mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users