• mysql中的NULL


    [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] >

  • 相关阅读:
    性能测试相关
    centos7 设置定时器 crond
    大杀器Bitset
    树形DP
    双线程DP
    状态压缩DP
    斜率优化DP
    01分数规划
    二分和三分
    uva11549 Floyd判圈法
  • 原文地址:https://www.cnblogs.com/smallfishy/p/12916895.html
Copyright © 2020-2023  润新知