数据库中有两种比较运算符<> 和!= ,它们是不是相同的意思呢?
经过考证,它们的意思的确相同,而且相关人员推荐使用<>,因为那是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
好了不多说了,还不懂的童鞋可以留言交流