让 mssql 发疯的语句. 最新 mssql server 的bug mssql server 7.0 和 mssql

  • 主题发起人 chshanghai
  • 开始时间
第一个例子了 我的分析跟你们的分析跟基本上差不多, 但我做第二个例子时
发现这种分析是不对的
test2:
table1 ( c1,c2) 表结构 下面的数据
1 ,1
1, 3
2, 3
select * from table1 where c1 in (select c2 from table2) //看好了是select c2 from table2
如果说上面这句相当于
select * from table1 where c1 in(c2)
那么结果应是
1,1
1, 2
但实际结果只有
1,1
为什么????????????
晕倒!!!!!!!!!!

to dirk
你果你认为你水平已经足以解决这个问题?????
但请你先解决这个问题先........然后再评价..








 
我可没说我是高手,我也不想评价什么,只是想对你说:不要见什么就大叫Bug,还最新的
Bug,你想想,这么一个基本的语句,这么多年,MS居然还搞不定,也太小瞧MS了,你起码
也该到其它的DBMS中求证一下再说嘛!
create table table1 (
a1 int,
a2 int
)
go
create table table2 (
c1 int,
c2 int
)
go
select * from table1
select * from table2
go
insert into table1 (a1,a2) values (1,1)
insert into table1 (a1,a2) values (1,2)
insert into table1 (a1,a2) values (1,3)
insert into table1 (a1,a2) values (2,3)
insert into table1 (a1,a2) values (2,2)
insert into table1 (a1,a2) values (2,2)
insert into table1 (a1,a2) values (2,1)
insert into table2 (c1,c2) values (9,9)
go
/*insert into table2 (c1,c2) values (1,1)
insert into table2 (c1,c2) values (1,2)
insert into table2 (c1,c2) values (1,3)
insert into table2 (c1,c2) values (2,3)
insert into table2 (c1,c2) values (9,9)
*/
select * from table1 where a1 in(a2)
select * from table1 where a1 in (select a2 from table2)
select * from table1 where a1 in (select a1 from table2)

看看结果,自己总结一下不就明白了?
select * from table1 where a1 in (a2)

select * from table1 where a1 in (select a2 from table2)
是等价的,很显然,如果table2没有记录,也即in子句空集,就相当于
select * from table1 where a1 in ()
如果table2有记录,则字段可以在table1中检索。

再次提醒,以上语句在DB2中结果相同,其它的DBMS不知是怎样处理,有兴趣可以试试,不
过,DB2的语法是最严谨的,DB2没问题其它的应该相同。
 
接受答案了.
 
顶部