MySQL查詢空字段或非空字段(is null和not null)
現(xiàn)在我們先來把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è)置一個字段值為空時的語法為:set <字段名>=NULL
說明一下,這里沒有大小寫的區(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)
接下來分別查詢一下字段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
關(guān)于MySQL查詢空字段或非空字段(is null和not null),本文就介紹這么多,希望對大家有所幫助,謝謝!
相關(guān)文章
MySQL同步數(shù)據(jù)Replication的實現(xiàn)步驟
本文主要介紹了MySQL同步數(shù)據(jù)Replication的實現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03MySQL5.7中 performance和sys schema中的監(jiān)控參數(shù)解釋(推薦)
在MySQL5.7中,performance schema有很大改進(jìn),包括引入大量新加入的監(jiān)控項、降低占用空間和負(fù)載,以及通過新的sys schema機(jī)制顯著提升易用性。下面通過本文給大家介紹 MySQL5.7中 performance和sys schema中的監(jiān)控參數(shù)解釋,需要的朋友可以參考下2017-08-08MySQL使用xtrabackup進(jìn)行備份還原操作
這篇文章主要為大家詳細(xì)介紹了MySQL如何使用xtrabackup進(jìn)行備份還原操作,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11mysql 8.0.16 winx64及Linux修改root用戶密碼 的方法
這篇文章主要介紹了mysql 8.0.16 winx64及Linux修改root用戶密碼 的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-07-07