0

Why are there two negation operators in SQL language? != and <>.

Are they redundant or is there a difference between them depending on operands ?

Which one should I use to negate strings in MySQL ?

Kamil Gosciminski
  • 16,547
  • 8
  • 49
  • 72
Badis Merabet
  • 13,970
  • 9
  • 40
  • 55

2 Answers2

5
  • <> is ISO Sql Standard
  • != is vendor specific

They both have no difference among them. It is just a personal preference which one to use. I always prefer <> since it is a ISO SQL standard

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Pரதீப்
  • 91,748
  • 19
  • 131
  • 172
2

The SQL standard only specifies <> for not equals. SQL:2011 Foundation, section 5.2 <token> and <separator> specifies:

<not equals operator> ::=
  <>

However some SQL implementations (like MySQL) also support != as a lot of programmers are more familiar with != for not equals. They are fully equivalent, so you can use either, but from a standards point of view you should use <>.

See also the MySQL documentation for not equals.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • I wouldn't say "most SQL implementations also support `!=`, but there is no reason for a downvote on this answer. – Gordon Linoff Dec 12 '15 at 12:43
  • @gordonlinoff I replaced it with some; I can't recall seeing one that didn't support it, but as I haven't seen all SQL implementations, most is likely not correct. Thanks. – Mark Rotteveel Dec 12 '15 at 14:10