【发布时间】:2011-10-14 09:59:39
【问题描述】:
好吧,也许我是 sql 的菜鸟,但我不明白为什么这应该起作用:
我喜欢 Table1:
IDRecord (PK), Description, IDTable2 (FK)
还有一个像这样的 Table2:
IDRecord (PK), Description
将 Table1.IDTable2 作为 Table2.IDRecord 的 FK。
然后我有一个非常简单的查询:
select * from Table1
where IDTable2 not in (select IDMispelledRecord from Table2)
我犯了一个语法错误! Table2中没有一个叫IDMispelledRecord的列,如果我单独执行子查询,它会返回给我
Invalid column name 'IDMispelledRecord'.
但如果我执行整个查询,它不会引发错误,只会返回 0 行。
谁能告诉我为什么?
【问题讨论】: