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
  • 15,392
  • 4
  • 45
  • 65
Badis Merabet
  • 11,902
  • 9
  • 38
  • 52

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
  • 90,369
  • 161
  • 124
  • 175
Pரதீப்
  • 88,697
  • 17
  • 124
  • 160
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
  • 90,369
  • 161
  • 124
  • 175
  • 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