数据库之!= OR <>

数据库中有两种比较运算符<> 和!= ,它们是不是相同的意思呢?

经过考证,它们的意思的确相同,而且相关人员推荐使用<>,因为那是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


好了不多说了,还不懂的童鞋可以留言交流



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值