數據庫中有兩種比較運算符<> 和!= ,它們是不是相同的意思呢?
經過考證,它們的意思的確相同,而且相關人員推薦使用<>,因爲那是98標準,可能支持的數據庫要多一些,但是主流的數據庫兩個運算時都支持的。
tips:
1. =some等價於 in運算
--teacher(ID varchar(10),salary numeric(5,0))
select * from teacher where salary=some (select salary from teacher)
--teacher(ID varchar(10),salary numeric(5,0))
select * from teacher where salary in (select salary from teacher)
以上兩段代碼的結果是相同的
2.****<>some 和not in 不相同****(畫重點)
--teacher(ID varchar(10),salary numeric(5,0))
select * from teacher where salary<>some (select salary from teacher)
只要teacher中老師的工資不只一種,該語句返回所有老師的紀錄
--teacher(ID varchar(10),salary numeric(5,0))
select * from teacher where salary not in (select salary from teacher)
以上語句返回空表,因爲老師的工資必然在子查詢之中(子查詢表示老師工資的集合)---貌似廢話
but why-----<>等價於!=也就是說,<>some 等價於!=some,即在外層查詢條件的值,在內層查詢之中存在與它不相等的值
例子:5<>some{0,1,5} 爲真,因爲存在0!=5
而5not in{0,1,5}爲假,因爲5在集合之中,存在5=5
好了不多說了,還不懂的童鞋可以留言交流