在MySQL中使用正确或更好的,不相等的运算符 [英] Using the correct, or preferable, not equal operator in MySQL

查看:162
本文介绍了在MySQL中使用正确或更好的,不相等的运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

测试不平等程度时,最好使用两种(在语义上等效)的方法?

Which of the two (semantically equivalent) ways is preferable to test for inequality?

  1. 'foo' != 'bar'(感叹号和等号)
  2. 'foo' <> 'bar'(小于和大于V形符号)
  1. 'foo' != 'bar' (exclamation mark and equals sign)
  2. 'foo' <> 'bar' (less than and greater than chevron symbols together)

MySQL文档清楚地表明它们之间没有区别,但是有些人似乎只喜欢以一种或另一种方式这样做.也许这只是vi与emacs争论的另一场毫无意义的事情,但是当其他人正在阅读您的代码(以及您的查询)时,保持某些一致性很有用.

The MySQL documentation clearly indicates that there is no difference between them and yet some people seem to be attached to only doing it one way or the other. Maybe this is just another pointless vi vs. emacs debate but when other people are reading your code (and therefore your queries), it's useful to maintain some consistency.

<>看起来很像<=>,这是一个未充分使用的运算符,但由于两者几乎相反(除了明显的NULL情况),可能一眼就能引起混乱.

<> looks a lot like <=> which is a very underused operator but could perhaps lead to confusion at a quick glance since the two are nearly opposite (except for the obvious NULL cases).

推荐答案

<>,因为它符合sql标准并且在技术上更具可移植性...

<> should be preferred, all things being equal, since it accords with the sql standard and is technically more portable...

!=是非标准的,但大多数数据库都实现了.

!= is non-standard, but most db's implement it.

sql:2008语法:

sql:2008 grammar:

<not equals operator> ::=
  <>

这篇关于在MySQL中使用正确或更好的,不相等的运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆