R
Richard Vevay
My impression is that the following query should not run / work, but it does.
The query is
select *
from tbl1 INNER JOIN qry1 ON tbl1.id = qry1.id
where
tbl2.field1 = "criteria2"
As it happens, tbl2.field1 is referenced in qry1. But shouldn't the
reference in the 'where' clause be to qr1.field1? I.e., shouldn't the
statement as written fail since tbl2 appears nowhere in the 'from' clause?
How can tbl2 be referenced in the 'where' clause??? Yet, this statement
works, and the selection results really are impacted by the last line of the
query.
For bonus points, explain why this SLIGHT modification to the above query
fails -- this modification attempts to reference tbl2 in the 'from' clause:
select *
from tbl3 INNER JOIN
(tbl1 INNER JOIN qry1 ON tbl1.id = qry1.id) ON tbl3.field1 = tbl2.field1
where tbl1.field1 = "criteria1" and
tbl2.field1 = "criteria2"
So the bottom line appears to be that a table which does NOT appear directly
in the 'from' clause may appear in the 'where' clause, but the same table may
NOT be referenced in the 'from' clause AS IF it had previously appeared. Is
this correct? Is this proper?
The query is
select *
from tbl1 INNER JOIN qry1 ON tbl1.id = qry1.id
where
tbl2.field1 = "criteria2"
As it happens, tbl2.field1 is referenced in qry1. But shouldn't the
reference in the 'where' clause be to qr1.field1? I.e., shouldn't the
statement as written fail since tbl2 appears nowhere in the 'from' clause?
How can tbl2 be referenced in the 'where' clause??? Yet, this statement
works, and the selection results really are impacted by the last line of the
query.
For bonus points, explain why this SLIGHT modification to the above query
fails -- this modification attempts to reference tbl2 in the 'from' clause:
select *
from tbl3 INNER JOIN
(tbl1 INNER JOIN qry1 ON tbl1.id = qry1.id) ON tbl3.field1 = tbl2.field1
where tbl1.field1 = "criteria1" and
tbl2.field1 = "criteria2"
So the bottom line appears to be that a table which does NOT appear directly
in the 'from' clause may appear in the 'where' clause, but the same table may
NOT be referenced in the 'from' clause AS IF it had previously appeared. Is
this correct? Is this proper?