Using the correct, or preferable, not equal operator in MySQL

谁说胖子不能爱 提交于 2019-11-28 09:36:17

<> 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 grammar:

<not equals operator> ::=
  <>

It's obvious.

The ! character is on the North West corner of US keyboards.

Microsoft headquarters are in the North West corner of the US.

So. <> is a nod to Microsoft.

!= is a rejection of Microsoft.

It's a secret political code.

<> is the only one in the SQL-92 standard.

DBA's generally like <> and programmers like !=. Just an observation :-)

They are the same, it is purely preference.

This should give you a good idea

Operators

!= (Not Equal To) Not equal to (not SQL-92 standard)

<> (Not Equal To) Not equal to

The <> operator is the one that is in the SQL standard, so most people that know SQL will be accustomed to it, or at least aware of it. I myself wasn't even aware of that the != operator was also available in some SQL dialects until recently.

As you noticed, people tend to use only one or the other, and that is a good approach, at least on a project-by-project basis. Whichever you choose to use, be consistent.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!