次のSQLを実行すると、SQLバージョン2005または2008 R2でエラーが発生しません。なぜT-SQLにエラーがありませんか?
select 1 as MyVal, 'string' as MyText
into #table1
select 1 as thisColumnDoesntExistInTable1, 'string' as MyText
into #table2
select * from #table1
select * from #table2
-- WHY NO ERROR HERE ---
select *
from #table2
where thisColumnDoesntExistInTable1 in
(
select thisColumnDoesntExistInTable1 from #table1
)
drop table #table1
drop table #table2
しかし、選択の内側にエイリアスを追加することによって、次のように文を変更した場合...
select *
from #table2
where thisColumnDoesntExistInTable1 in
(
select a.thisColumnDoesntExistInTable1 from #table1 a
)
...あなたがエラーを取得しません。