IS NOT NULL

语法说明

IS NOT NULL 运算符用于判断列的值是否为空。如果值不为空,即不为 NULL,则返回 true,否则返回 false。它可以用于 SELECTINSERTUPDATEDELETE 语句。

语法结构

  1. > expression IS NOT NULL

示例

  1. mysql> SELECT 1 IS NOT NULL, 0 IS NOT NULL, NULL IS NOT NULL;
  2. +---------------+---------------+------------------+
  3. | 1 is not null | 0 is not null | null is not null |
  4. +---------------+---------------+------------------+
  5. | true | true | false |
  6. +---------------+---------------+------------------+
  7. 1 row in set (0.01 sec)
  1. create table t1 (a boolean,b bool);
  2. insert into t1 values (0,1),(true,false),(true,1),(0,false),(NULL,NULL);
  3. mysql> select * from t1;
  4. +-------+-------+
  5. | a | b |
  6. +-------+-------+
  7. | false | true |
  8. | true | false |
  9. | true | true |
  10. | false | false |
  11. | NULL | NULL |
  12. +-------+-------+
  13. mysql> select * from t1 where b is NOT NULL;
  14. +-------+-------+
  15. | a | b |
  16. +-------+-------+
  17. | false | true |
  18. | true | false |
  19. | true | true |
  20. | false | false |
  21. +-------+-------+
  22. 4 rows in set (0.01 sec)