MySQL数据库—— null = null 与 null &It;=> null 查询结果是什么呢?

一、普通的 null 查询

----数据表----

mysql> select * from person;
+------+--------+-------+
| id   | name   | phone |
+------+--------+-------+
|    1 | 李白   | 10086 |
|    2 | 杜甫   | NULL  |
|    3 | 陶渊明 | NULL  |
+------+--------+-------+
3 rows in set (0.00 sec)

----查询其中 phone 不为空的 name ----

mysql> select name,phone from person where phone is not null;
+------+-------+
| name | phone |
+------+-------+
| 李白 | 10086 |
+------+-------+
1 row in set (0.00 sec)

二、null = null 

mysql> select null = null,null = 1,null = 2;
+-------------+----------+----------+
| null = null | null = 1 | null = 2 |
+-------------+----------+----------+
|        NULL |     NULL |     NULL |
+-------------+----------+----------+
1 row in set (0.00 sec)

三、  null <=> null

mysql> select null <=> null,null <=> 1,null <=> 2;
+---------------+------------+------------+
| null <=> null | null <=> 1 | null <=> 2 |
+---------------+------------+------------+
|             1 |          0 |          0 |
+---------------+------------+------------+
1 row in set (0.00 sec)

那么 = 与 <=> 有什么区别呢?

MySQL中的比较运算符:

MySQL数据库—— null = null 与 null &It;=> null 查询结果是什么呢?_第1张图片

你可能感兴趣的:(MySQL)