问题
The sql statement below will not run in SQLite:
select *
from A
left join (B inner join C on B.fkC = C.pk) on A.optionalfkB = B.pk
I get a sqlException "unknown column B.pk"
According to the documentation @ http://www.sqlite.org/lang_select.html this should work, and it will work in all other sql implementations. Am I doing something wrong?
回答1:
It doesn't work because the "outer" query doesn't know what B is.
select *
from A
left join (B inner join C on B.fkC = C.pk) B on A.optionalfkB = B.pk
The (B inner join C on B.fkC = C.pk)
is weird without any select
, but the specification does say that it is valid.
来源:https://stackoverflow.com/questions/7071283/problem-with-nested-inner-joins-in-sqlite