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

  • 主题发起人 chshanghai
  • 开始时间
C

chshanghai

Unregistered / Unconfirmed
GUEST, unregistred user!
让 mssql 发疯的语句. 最新 mssql server 的bug mssql server 7.0 和 mssql server 2000都有??? (10分)<br />假设有一个表
table1 ( c1,c2 )
table2 ( d1,d2,)
test1:
你试试下面的语句
select * from table1 where c1 in (select c1 from table2) //看好了是select c1 from table2

你猜猜结算是什么
--报错?
NO !

是 table1 中的所有记录... ??????????????

test2 :
还是上面的表 只是加了几行数据
table1 ( c1,c2) 表结构 下面的数据
1 ,1
1, 3
2, 3

select * from table1 where c1 in (select c2 from table2) //看好了是select c2 from table2


结果是什么 ???
是所有记录???

NO
是 1 ,1


[:D][:D][:D][:D][:D][:D]
晕倒!!!!!!!!!!!!!!!!!







 
select c1 from table2 ?
请问table2中有c1这个字段吗?
 
对啊. 正是因为没有但 mssql 不报错
知道为什么????????????
 
select * from orders where orderid in (select orderid from [order details])
这样没问题啊
 
我的结果与你的不一样,test1为空,没有报错
 
只要是在这两个表里面能找到的字段,放在in 后面的都 不会出错,这可能是它的bug
 
to aefhh
可能是你的table2 中没有记录, 你添加几条记录试试
 
有意思,这你也能发现.^_^
 
呵, 偶然而已.
 
SELECT *
FROM Orders
WHERE orderid IN
(SELECT customerid
FROM employees)
我怎么什么也没发现 use Northwind database 'customerid' column in 'orders' table
but not in 'employees' table
 
你试试下面这个
SELECT *
FROM Orders
WHERE orderid IN
( SELECT orderid
FROM employees)
 
废话,这当然成立!
select * from table1 where c1 in (select c1 from table2)
相当与
select * from table1 where c1 in c1

这何止是MS SQLServer,连IBM DB2 都是这样!
 
同样:
select * from table1 where c1 in (select c2 from table2)
相当与
select * from table1 where c1 in c2
 
to dirk:
select * from table1 where c1 in c1在MSSQL会报错,但我觉得执行的流程应该是这样吧!
 
我想是这样吧!如果c1在table1中找不到就造成在前面的表中(table1)找!
所以以上的sql应该被转换成select * from table1 where c1 in (select c1 from table1)
进一步就是select * from table1 where c1 in (select c1)吧!
 
同意!
select * from table1 where c1 in (select c2 from table2)
没有规定子查询不能选择前面的表字段啊!
你们说:
select * from table1 where c1 in (select 1 from table2)
成不成立????

这应该是一个逻辑上的问题吧?!
 
我不过随便写写,没写完整罢了
select * from table1 where c1 in (c1)
这样SQLServer总不报错了吧?

另外
select * from table1 where c1 in c1
这种写法在DB2中是合法的,DB2的SQL语法是最规范的了!
 
网络男孩:下面这句话可是你说的

我想是这样吧!如果c1在table1中找不到就造成在前面的表中(table1)找!
 
顶部