MySQL查詢空字段或非空字段(is null和not null)
現(xiàn)在我們先來(lái)把test表中的一條記錄的birth字段設(shè)置為空。
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,執(zhí)行成功!
設(shè)置一個(gè)字段值為空時(shí)的語(yǔ)法為:set <字段名>=NULL
說(shuō)明一下,這里沒有大小寫的區(qū)分,可以是null,也可以是NULL。
下面看看結(jié)果:
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)
接下來(lái)分別查詢一下字段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)
說(shuō)明:
1、查詢字段值為空的語(yǔ)法:where <字段名> is null
2、查詢字段值不為空的語(yǔ)法:where <字段名> is not null
關(guān)于MySQL查詢空字段或非空字段(is null和not null),本文就介紹這么多,希望對(duì)大家有所幫助,謝謝!
相關(guān)文章
MySQL pt-slave-restart工具的使用簡(jiǎn)介
這篇文章主要介紹了MySQL pt-slave-restart工具的使用簡(jiǎn)介,幫助大家更好的理解和學(xué)習(xí)使用MySQL,感興趣的朋友可以了解下2021-04-04
MySQL數(shù)據(jù)庫(kù)事務(wù)隔離級(jí)別介紹(Transaction Isolation Level)
這篇文章主要介紹了MySQL數(shù)據(jù)庫(kù)事務(wù)隔離級(jí)別(Transaction Isolation Level) ,需要的朋友可以參考下2014-05-05
詳解MySQL like如何查詢包含''%''的字段(ESCAPE用法)
這篇文章主要介紹了詳解MySQL like如何查詢包含'%'的字段(ESCAPE用法),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12

