MySQL queries empty or non-empty fields (is null and not null), mysqlnull

Source: Internet
Author: User

MySQL queries empty or non-empty fields (is null and not null), mysqlnull

Now let's set the birth field of a 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 successful!
When a field value is set to NULL, the syntax is set <field Name> = NULL.
Note: There is no case sensitivity. It can be null or NULL.

The result is as follows:

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, query the records with the t_birth value being null or not:

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)

Note:
1. syntax for querying empty field values: where <field Name> is null
2. syntax for querying field values not empty: where <field Name> is not null

This article describes how to query empty or non-empty fields (is null and not null) in MySQL. I hope this will help you. Thank you!

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.