日期:2014-05-18  浏览次数:20721 次

解释一条Sql语句:
select   A.Item_ID   From   A   Not   In(select   B.Item_ID   From   B)
select   A.Item_ID   From   A   Not   In(select   A.Item_ID   From   B)
这两句的区别?

------解决方案--------------------
下面这句:select A.Item_ID From B
b里面要包含a.item_ID的列名!!
------解决方案--------------------
select B.Item_ID From B)
(select A.Item_ID From B)
--
取的不同的表
不过
select A.Item_ID From A Not In(select A.Item_ID From B) //这句话能执行,我怀疑
------解决方案--------------------
直接怀疑你这SQL能执行不?
------解决方案--------------------
不太明白
------解决方案--------------------
select A.Item_ID From A Not In(select A.Item_ID From B)


这句话可以执行么
------解决方案--------------------
经测试
下面两句话没有一句是队的(mssql2000)
select A.Item_ID From A Not In(select B.Item_ID From B)
select A.Item_ID From A Not In(select A.Item_ID From B)

---------------------
CREATE TABLE [dbo].[A] (
[item_id] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,
[col] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,
[col1] [char] (10) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[B] (
[item_id] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,
[col] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,
[col1] [char] (10) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
------解决方案--------------------
如果能执行,我猜测:
select A.Item_ID From A Not In(select A.Item_ID From B)
等同于
select A.Item_ID From A Not In(NULL)
即等同于
select A.Item_ID From A


------解决方案--------------------
A表
item_ID
1
2
3
b表
item_ID
2
3
4

select A.Item_ID From A where item_id Not In(select B.Item_ID From B)
--结果1
select A.Item_ID From A where item_id Not In(select A.Item_ID From B)
--没有结果



------解决方案--------------------
select A.Item_ID From A where a.item_id Not In(select B.Item_ID From B)
select A.Item_ID From A where a.item_id Not In(select A.Item_ID From B)
这样就可以啦。。可能是LZ笔误了。
------解决方案--------------------
也许楼主的数据库和我门的不一样
------解决方案--------------------
sqlserver2000的测试结果
select A.Item_ID From A where item_id Not In(select A.Item_ID From B)

等同于

select A.Item_ID From A where item_id Not In(select A.Item_ID From a)