0

MySQL supports 2 different not equal operators, != and <>.

Is there any difference in functionality between the two where you would want to use 1 instead of the other in specific situations?

ryanzec
  • 27,284
  • 38
  • 112
  • 169

3 Answers3

1

They are the same. Both are two Not Equal To operators. But != is not ISO standard.

!=
Tests whether one expression is not equal to another expression (a comparison operator). If either or both operands are NULL, NULL is returned. Functions the same as the <> (Not Equal To) comparison operator.

<>
Compares two expressions (a comparison operator). When you compare nonnull expressions, the result is TRUE if the left operand is not equal to the right operand; otherwise, the result is FALSE.

Up_One
  • 5,213
  • 3
  • 33
  • 65
1

There is no difference in MySQL between the two, they both behave the same. However <> is standard SQL so if you get used to using that then you won't have any problems if you move to a RDBMS that doesn't support !=

RMcLeod
  • 2,561
  • 1
  • 22
  • 38
0

As Adriano said before, exactly the same, see documentation: https://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html

The question does show considerable lack of research.

Justin Mitchell
  • 339
  • 1
  • 5
  • Your final sentence is unnecessary. – crush Apr 03 '14 at 11:28
  • It's 1 Google search straight to the developers documentation and it lists that both operators operate the same way. As Up_One mentioned in his resonse, != is not standard whilst many developers will be familiar with it, whereas <> is standard and widely implemented in just about every database system. – Justin Mitchell Apr 03 '14 at 11:32
  • Which is something the documentation doesn't mention. I don't know about you, but I don't live in a world where documentation is always 100% complete either. Regardless, your rude comments add nothing to your answer. If you feel you must make them, then they belong in a comment... – crush Apr 03 '14 at 11:35
  • That's fair enough, but documentation is supposed to be a starting point at the very least. Here's an answer to this question already: http://stackoverflow.com/questions/2066987/using-the-correct-or-preferable-not-equal-operator-in-mysql and you already pointed it out... so... – Justin Mitchell Apr 03 '14 at 11:39
  • The question states 'Is there any difference in functionality...' - the manual answers that exactly. Whether or not one is better in general is debatable and a matter of opinion. – Vatev Apr 03 '14 at 11:39
  • @JustinMitchell I did look at the MySQL documentation before posting this question. The reason I asked this querytion is because I saw some code that referenced != as 'not equals' and <> and 'basic not equals' and the documentation does not explicitly say those 2 operators function the same. I assumed that the documentation would have mentioned if there was a functional difference between the two however it would not be the first time that type of assumption based on document was not correct. – ryanzec Apr 03 '14 at 12:14