您好,欢迎访问一九零五行业门户网

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 7d7db3eee304faccc5db90e2b256afeb is null
2、查询字段值不为空的语法:where 7d7db3eee304faccc5db90e2b256afeb is not null
以上就是mysql查询空字段或非空字段(is null和not null)_mysql的内容。
其它类似信息

推荐信息