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