我是靠谱客的博主 柔弱小蜜蜂,这篇文章主要介绍mysql 非空语法_MySQL查询空字段或非空字段(is null和not null)_MySQL,现在分享给大家,希望可以做个参考。

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

现在我们先来把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)_MySQL的内容,更多相关内容请关注PHP中文网(www.php.cn)!

f68f2add0b68e4f9810432fce46917b7.png

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

最后

以上就是柔弱小蜜蜂最近收集整理的关于mysql 非空语法_MySQL查询空字段或非空字段(is null和not null)_MySQL的全部内容,更多相关mysql内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(148)

评论列表共有 0 条评论

立即
投稿
返回
顶部