When I try to make a subquery with left join
, I got an error here.
Select * FROM ( SELECT Code,Column2 FROM T1) TSubQuery, Table2 T2
Left join Table3 T3
On T3.Code = TSubQuery.Code
Where TSubQuery.Code= T2.Code
this code causes the following error:
Msg 4104, Level 16, State 1, Line 3 Multiple identifier "TSubQuery.Code" cannot be bound.
So, I solved this problem by changing mine Where
to a suggestion Inner join
.
Select * FROM ( SELECT Code,Column2 FROM T1) TSubQuery
Left join Table3 T3
On T3.Code = TSubQuery.Code
Inner join Table2 T2
On T2.Code = TSubQuery.Code
I would like to understand why I have this error?
is there any other way to solve it without using Inner join
or with with clause
?
Why don't I have this problem when I use a regular table or with with table
?
Example:
With TQuery as ( SELECT * FROM T1)
select * from TQuery, Table2 T2
Left join Table3 T3
On T3.Code = TQuery.Code
Where TQuery.Code = T2.Code
source
share