36

If I use a simple table such as :

create table test ( a int );
insert into test values ( 1 ) , ( 2 ) , ( 2 ) , ( 3 );
select * from test where a <> 2;
select * from test where a != 2;

Both give me :

+------+
| a    |
+------+
|    1 |
|    3 |
+------+
2 rows in set (0.00 sec)

So what is the difference between <> and != mysql operators ?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Alain Tiemblo
  • 36,099
  • 17
  • 121
  • 153

4 Answers4

32

<> 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> ::=
  <>
echo_Me
  • 37,078
  • 5
  • 58
  • 78
30

They are both exactly the same. See the documentation.

http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_not-equal

anothershrubery
  • 20,461
  • 14
  • 53
  • 98
7

No difference. <> is sql standard, != non-standard.

Hamlet Hakobyan
  • 32,965
  • 6
  • 52
  • 68
3

Nothing. Simply two different ways of writing the same thing

Kevin
  • 7,162
  • 11
  • 46
  • 70