程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> 其他數據庫知識 >> MSSQL >> 被遺忘的SQLServer比擬運算符謂詞

被遺忘的SQLServer比擬運算符謂詞

編輯:MSSQL

被遺忘的SQLServer比擬運算符謂詞。本站提示廣大學習愛好者:(被遺忘的SQLServer比擬運算符謂詞)文章只能為提供參考,不一定能成為您想要的結果。以下是被遺忘的SQLServer比擬運算符謂詞正文


官方的參考文檔
http://technet.microsoft.com/zh-cn/library/ms187074%28SQL.90%29.aspx
他們感化於比擬運算符和子查詢之間,感化相似Exists、not exists、in、not in和其他邏輯意義,這些語法異樣被SQLServer2000支撐然則很少看到有人用它們。

set nocount on
use tempdb
go
if (object_id ('t1' ) is not null ) drop table t1
create table t1 (n int )
insert into t1 select 2 union select 3
if (object_id ('t2' ) is not null ) drop table t2
create table t2 (n int )
insert into t2 select 1 union select 2 union select 3 union select 4
select * from t2 where n> all (select n from t1 ) --4
select * from t2 where n> any (select n from t1 ) --3,4
--select * from t2 where n>some(select n from t1) --3,4
select * from t2 where n= all (select n from t1 ) --有數據
select * from t2 where n= any (select n from t1 ) --2,3
--select * from t2 where n=some(select n from t1) --2,3
select * from t2 where n< all (select n from t1 ) --1
select * from t2 where n< any (select n from t1 ) --1,2
--select * from t2 where n<some(select n from t1) --1,2
select * from t2 where n<> all (select n from t1 ) --1,4
select * from t2 where n<> any (select n from t1 ) --1,2,3,4
--select * from t2 where n<>some(select n from t1)--1,2,3,4
set nocount off

留意,假如t1中包括null數據,那末一切All相干的比擬運算將不會前往任何成果,緣由就不消多說明了。而由於t1和t2表的null的存在他們和not exists之類的比擬符會有一些差別。
好比上面兩句
select * from t2 a where not exists(select 1 from t1 where n>=a.n)
select * from t2 where n >all(select n from t1)
他們邏輯上意義很像然則關於null的處置倒是恰好相反,第一句會疏忽子查詢的null而把t2的null同時查出來,第二句倒是疏忽了t2的null同時會由於t1中的null而沒法查詢到數據。
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved