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。
狼蚁网站SEO优化看看结果:
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),本文就介绍这么多,希望对大家有所帮助,谢谢!
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程