《Mysql入門MySQL查詢空字段或非空字段(is null和not null)》要點(diǎn):
本文介紹了Mysql入門MySQL查詢空字段或非空字段(is null和not null),希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
MYSQL實(shí)例現(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ō)明一下,這里沒(méi)有大小寫的區(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ì)大家有所幫助,謝謝!?
維易PHP培訓(xùn)學(xué)院每天發(fā)布《Mysql入門MySQL查詢空字段或非空字段(is null和not null)》等實(shí)戰(zhàn)技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養(yǎng)人才。
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.snjht.com/jiaocheng/10511.html