[mysql - root@localhost@testmysql.sock 23:44:48] >select * from a;
+------+------+ --------------a表中包含a,c,无NULL
| a | c |
+------+------+
| 2 | 1 |
| 3 | 1 |
| 1 | 2 |
+------+------+
3 rows in set (0.00 sec)
[mysql - root@localhost@testmysql.sock 23:44:52] >select * from b;
+------+------+ --------------b表中包含a,c,b列有NULL
| a | b |
+------+------+
| 1 | 2 |
| 3 | 2 |
| 3 | NULL |
+------+------+
3 rows in set (0.00 sec)
[mysql - root@localhost@testmysql.sock 23:46:46] >select a.a,a.c,b.b from a,b where a.a=b.a and b.b is NULL; -------这两个查询很容易理解
+------+------+------+
| a | c | b |
+------+------+------+
| 3 | 1 | NULL |
+------+------+------+
1 row in set (0.00 sec)
[mysql - root@localhost@testmysql.sock 23:47:04] >select a.a,a.c,b.b from a,b where a.a=b.a and b.b is not NULL; -------这两个查询很容易理解
+------+------+------+
| a | c | b |
+------+------+------+
| 3 | 1 | 2 |
| 1 | 2 | 2 |
+------+------+------+
2 rows in set (0.00 sec)
[mysql - root@localhost@testmysql.sock 23:48:20] >select * from a where a.a in (select b.a from b where b.b is NULL); -----b表中虽然有NULL,但是把b.a作为关联条件,也不会有问题
+------+------+
| a | c |
+------+------+
| 3 | 1 |
+------+------+
1 row in set (0.00 sec)
[mysql - root@localhost@testmysql.sock 23:48:35] >select * from a where a.a in (select b.a from b where b.b is not NULL); -----b表中虽然有NULL,但是把b.a作为关联条件,也不会有问题
+------+------+
| a | c |
+------+------+
| 1 | 2 |
| 3 | 1 |
+------+------+
2 rows in set (0.00 sec)
[mysql - root@localhost@testmysql.sock 23:48:46] >select * from a where a.a in (select b.b from b where b.b is not NULL); ----b表中虽然有NULL,但是把b.b作为关联条件,一不小心就中招儿了
+------+------+
| a | c |
+------+------+
| 2 | 1 |
+------+------+
1 row in set (0.00 sec)
[mysql - root@localhost@testmysql.sock 23:49:46] >select * from a where a.a in (select b.b from b where b.b is NULL); ----b表中虽然有NULL,但是把b.b作为关联条件,一不小心就中招儿了
Empty set (0.00 sec) ----b.b的结果是NULL,因此a的结果也只能是空
[mysql - root@localhost@testmysql.sock 23:49:54] >
[mysql - root@localhost@testmysql.sock 23:55:06] >select ''='';
+-------+
| ''='' |
+-------+
| 1 |
+-------+
1 row in set (0.00 sec)
[mysql - root@localhost@testmysql.sock 23:55:10] >select NULL='';
+---------+
| NULL='' |
+---------+
| NULL |
+---------+
1 row in set (0.00 sec)
[mysql - root@localhost@testmysql.sock 23:55:15] >select NULL=NULL;
+-----------+ -----NULL不与任何相等,包括NULL
| NULL=NULL |
+-----------+
| NULL |
+-----------+
1 row in set (0.00 sec)
[mysql - root@localhost@testmysql.sock 23:55:17] >