40

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 ?

1
  • I can't find any documentation explicitly saying so, but they are synonymous. Commented Jan 4, 2013 at 15:03

4 Answers 4

35

<> 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> ::=
  <>
Sign up to request clarification or add additional context in comments.

3 Comments

why is it technically more portable?
@Dennis I guess because it is sql standard.
@Dennis it should be more compatible to use <> and easily to transplant the query in different RDBMS. so it's considering portable?
34

They are both exactly the same. See the documentation.

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

2 Comments

Thank you, strange notation. Just seen that on a coworker code and just got stuck.
Yeah, while I use C-based languages mainly I tend to use <> even though != feels more natural to me. <> just seems right for any SQL representation.
7

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

Comments

3

Nothing. Simply two different ways of writing the same thing

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.