Mysql query Empty or non-empty fields (is null and NOT NULL) _mysql

Source: Internet
Author: User
Tags mysql query

Now let's set the birth field of one record in the test table to null.

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, execution is successful!
The syntax for setting a field value to NULL is: Set < field name >=null
To illustrate, there is no case-sensitive distinction, can be null, or it can be null.

Here's a look at the results:

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)

Next, check out the records for which the field T_birth value is blank or not blank:

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 are NOT null;
+------+--------+----------------------------------+------------+
| t_id | T_name | T_password | T_birth |
+------+--------+----------------------------------+------------+
| 2 | name2 | 12345678901234567890123456789012 | 2013-01-01 |
+------+--------+----------------------------------+------------+
1 row in Set (0.00 sec)

Description
1. Syntax for null query field value: where < field name > is null
2. Syntax for query field value NOT NULL: where < Field name > is NOT NULL

About MySQL query empty fields or Non-null fields (is null and NOT NULL), this article on the introduction of so many, I hope to help you, thank you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.