开发者

SQL Server 2008 subquery with error. Still works the main query

开发者 https://www.devze.com 2023-04-12 19:29 出处:网络
Ok, maybe I\'m a noob in sql, but I can\'t figure out why this should work: I\'ve Table1 like: IDRecord (PK), Description, IDTable2 (FK)

Ok, maybe I'm a noob in sql, but I can't figure out why this should work:

I've Table1 like:

IDRecord (PK), Description, IDTable2 (FK)

and a Table2 like this:

IDRecord (PK), Description

with Table1.IDTable2 as FK to Table2.IDRecord.

Then I've a very simple query:

select * from Table1
where IDTable2 not in (select IDMispelledRecord from Table2)

I've made a syntax error! There's not a column called IDMispelledRecord in Table2, and if I execute the subquery alone, it returns to me

Invalid column name 'IDMispelledRecord'.

But if I execute the WHOLE query it doesn't raise an error, simply returns 0 rows.

Can开发者_如何学Go anyone tell me why?


Though your question doesn't show this (please post your actual code in future) Table1 must have a column called IDMispelledRecord.

Your subquery is referencing that column from the outer query.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号