[英]What does “<=>” in MySQL mean?
MySQL中的<=>
是什么意思和做什么?
The manual says it all: 手册说明了一切:
NULL-safe equal.
NULL安全相等。 This operator performs an equality comparison like the = operator, but returns 1 rather than NULL if both operands are NULL, and 0 rather than NULL if one operand is NULL.
此运算符执行与=运算符类似的相等比较,但如果两个操作数均为NULL,则返回1而不是NULL;如果一个操作数为NULL,则返回0而不是NULL。
mysql> select NULL <=> NULL;
+---------------+
| NULL <=> NULL |
+---------------+
| 1 |
+---------------+
1 row in set (0.00 sec)
mysql> select NULL = NULL;
+-------------+
| NULL = NULL |
+-------------+
| NULL |
+-------------+
1 row in set (0.00 sec)
mysql> select NULL <=> 1;
+------------+
| NULL <=> 1 |
+------------+
| 0 |
+------------+
1 row in set (0.00 sec)
mysql> select NULL = 1;
+----------+
| NULL = 1 |
+----------+
| NULL |
+----------+
1 row in set (0.00 sec)
mysql>
It's the NULL-safe equal operator . 它是NULL安全的等于运算符 。
The difference between <=> and = is when one or both of the operands are NULL values. <=>和=之间的区别是当一个或两个操作数都是NULL值时。 For example:
例如:
NULL <=> NULL gives True
NULL = NULL gives NULL
Here is the full table for the <=>
comparison of values 1, 2 and NULL: 以下是
<=>
值1,2和NULL的比较的完整表:
| 1 2 NULL -----+------------------- 1 | True False False 2 | False True False NULL | False False True
Compare to the ordinary equality operator: 与普通的相等运算符比较:
| 1 2 NULL -----+------------------- 1 | True False NULL 2 | False True NULL NULL | NULL NULL NULL
NULL-safe equal to operator NULL-safe等于运算符
http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_equal-to http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_equal-to
<=>
is a so called NULL
-safe-equality operator . <=>
是一个所谓的NULL
-safe-equality运算符 。
SELECT 1 <=> 1, NULL <=> NULL, 1 <=> NULL;
-> 1, 1, 0
SELECT 1 = 1, NULL = NULL, 1 = NULL;
-> 1, NULL, NULL
它与SQL标准关键字DISTINCT相同
SELECT * FROM somewhere WHERE `address1` is not distinct from `address2`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.