what does “delete from table where NULL = NULL” means?

前端 未结 8 1513
抹茶落季
抹茶落季 2021-02-18 12:35

What does delete from table where NULL = NULL mean?

8条回答
  •  星月不相逢
    2021-02-18 13:13

    Recap:

    mysql> select null = null, null <> null, null is null, null = 1, null <> 1;
    +-------------+--------------+--------------+----------+-----------+
    | null = null | null <> null | null is null | null = 1 | null <> 1 |
    +-------------+--------------+--------------+----------+-----------+
    |        NULL |         NULL |            1 |     NULL |      NULL |
    +-------------+--------------+--------------+----------+-----------+
    1 row in set (0.00 sec)
    
    
    mysql> select count(*) from table;
    +----------+
    | count(*) |
    +----------+
    |     10   |
    +----------+
    1 row in set (0.33 sec)
    
    
    mysql> select * from table where null;
    Empty set (0.00 sec)
    

    Meaning, if a condition evaluates to null it is considered false by MySql so delete from table where NULL = NULL will in fact delete nothing.

    NULL is a special beast as noted by Codd

提交回复
热议问题