《Mysql入門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 <字段名> is null
2、查詢字段值不為空的語法:where <字段名> is not null
關于MySQL查詢空字段或非空字段(is null和not null),本文就介紹這么多,希望對大家有所幫助,謝謝!?
維易PHP培訓學院每天發布《Mysql入門MySQL查詢空字段或非空字段(is null和not null)》等實戰技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養人才。