Which of the two (semantically equivalent) ways is preferable to test for inequality?
'foo' != 'bar'
(exclamation mark and equals sign)'foo' <> 'bar'
(less than and greater than chevron symbols together)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.
<>
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).
<> 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> ::=
<>