On 11/5/17, Shane Dev <devshan...@gmail.com> wrote: > > In sqlite3, I executed the following statements - > > sqlite> select name from tabs where rowid=1; > tab1 > sqlite> select * from tab1; > first rec > > sqlite> select * from (select name from tabs where rowid=1); > tab1 > > I expected the last statement to evaluate the subquery first to be 'tab1' > and then execute SELECT * FROM tab1 to yield 'first rec'. Why didn't this > happen?
Because that is not the way SQL works. The statement SELECT * FROM (SELECT name FROM tabs WHERE rowid=1); is logically equivalent to: CREATE TEMP TABLE "some-random-name" AS SELECT name FROM tabs WHERE rowid=1; SELECT * FROM "some-random-name"; DROP TABLE "some-random-name"; SQL works on a compile-then-execute model. Each SQL statement is first analyzed and compiled into bytecode or into machine code or some other executable format. Then the resulting compiled code is run to generate a result. The names of tables and columns are fixed at compile-time and cannot be modified at runtime, since to do so would require on-the-fly changes to the compiled code. -- D. Richard Hipp d...@sqlite.org _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users