MySQL 中 <> 和 != 运算符有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14159569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:02:15  来源:igfitidea点击:

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

mysqloperators

提问by Alain Tiemblo

Possible Duplicate:
Should I use != or <> for not equal in TSQL?

可能的重复:
我应该在 TSQL 中使用 != 还是 <> 表示不相等?

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 ?

那么<>!=mysql操作符有什么区别呢?

采纳答案by anothershrubery

回答by echo_Me

<>should be preferred, all things being equal, since it accords with the sql standard and is technically more portable...

<>应该是首选,所有事情都是平等的,因为它符合 sql 标准并且在技术上更易于移植......

!=is non-standard, but most db's implement it.

!=是非标准的,但大多数数据库都实现了它。

sql:2008 grammar:

sql:2008 语法:

<not equals operator> ::=
  <>

回答by Hamlet Hakobyan

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

没有不同。<>是sql标准的,!=非标准的。

回答by Kevin

Nothing. Simply two different ways of writing the same thing

没有。只是写同一件事的两种不同方式