Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between <> and != operators in MySQL? [duplicate]

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 ?

like image 996
Alain Tiemblo Avatar asked Jan 04 '13 15:01

Alain Tiemblo


People also ask

What is difference between <> and != In SQL?

Difference between SQL Not Equal Operator <> and != to do inequality test between two expressions. Both operators give the same output. The only difference is that '<>' is in line with the ISO standard while '!= ' does not follow ISO standard.

Which one is faster between <> and != MySQL?

There is no difference. According to SQL.org, the !=

What is difference between <> and NOT operators?

Here is the answer – Technically there is no difference between != and <>. Both of them work the same way and there is absolutely no difference in terms of performance or result. Here is the follow up question I received right I answer that there is no difference between those operator.

What does != Mean in MySQL?

not equal to (<>, !=) operator. MySQL Not equal is used to return a set of rows (from a table) after making sure that two expressions placed on either side of the NOT EQUAL TO (<>) operator are not equal. Syntax: <>, !=


2 Answers

<> 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> ::=   <> 
like image 71
echo_Me Avatar answered Sep 21 '22 19:09

echo_Me


They are both exactly the same. See the documentation.

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

like image 38
anothershrubery Avatar answered Sep 24 '22 19:09

anothershrubery