mysql not null 和空_MySQL查询空字段或非空字段(is null和not null)

现在我们先来把test表中的一条记录的birth字段设置为空。

mysql> update test set t_birth=null where t_id=1;

Query OK, 1 row affected (0.02 sec)

Rows matched: 1 Changed: 1 Warnings: 0

OK,执行成功!

设置一个字段值为空时的语法为:set =NULL

说明一下,这里没有大小写的区分,可以是null,也可以是NULL。

下面看看结果:

mysql> select * from test;

+------+--------+----------------------------------+------------+

| t_id | t_name | t_password | t_birth |

+------+--------+----------------------------------+------------+

| 1 | name1 | 12345678901234567890123456789012 | NULL |

| 2 | name2 | 12345678901234567890123456789012 | 2013-01-01 |

+------+--------+----------------------------------+------------+

2 rows in set (0.00 sec)

接下来分别查询一下字段t_birth值为空或不为空的记录:

mysql> select * from test where t_birth is null;

+------+--------+----------------------------------+---------+

| t_id | t_name | t_password | t_birth |

+------+--------+----------------------------------+---------+

| 1 | name1 | 12345678901234567890123456789012 | NULL |

+------+--------+----------------------------------+---------+

1 row in set (0.00 sec)

mysql> select * from test where t_birth is not null;

+------+--------+----------------------------------+------------+

| t_id | t_name | t_password | t_birth |

+------+--------+----------------------------------+------------+

| 2 | name2 | 12345678901234567890123456789012 | 2013-01-01 |

+------+--------+----------------------------------+------------+

1 row in set (0.00 sec)

说明:

1、查询字段值为空的语法:where is null

2、查询字段值不为空的语法:where is not null

关于MySQL查询空字段或非空字段(is null和not null),本文就介绍这么多,希望对大家有所帮助,谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值