33

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
  • 963,270
  • 265
  • 3,804
  • 3,187
Alain Tiemblo
  • 34,627
  • 15
  • 118
  • 149

4 Answers4

29

<> 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
  • 36,552
  • 5
  • 55
  • 77
28

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
  • 19,639
  • 11
  • 51
  • 94
6

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

Hamlet Hakobyan
  • 32,360
  • 6
  • 50
  • 66
2

Nothing. Simply two different ways of writing the same thing

Kevin
  • 6,921
  • 10
  • 44
  • 70