MySQL查詢空字段或非空字段(is null和not null)。本站提示廣大學習愛好者:(MySQL查詢空字段或非空字段(is null和not null))文章只能為提供參考,不一定能成為您想要的結果。以下是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。
上面看看成果:
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),本文就引見這麼多,願望對年夜家有所贊助,感謝!