MySQL query for empty or non-null fields (is null and not null)

Key words

MySQL field NULL

Summary

This article describes how to query a field with an empty (NULL) value in MySQL. How to judge the value of a field is NULL or not NULL?
 

This article describes how to query a field with an empty (NULL) value in MySQL. How to judge the value of a field is NULL or not NULL?

Now let's set the birth field of a record in the test table to be empty.

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, successful execution!
The syntax for setting a field value to be empty is: set <field name>=NULL
Explain that there is no case distinction here, it can be null or NULL.

Take a look at the results below:

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 field t_birth value is empty or not empty The record for:

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)

Description:
1. The syntax of the query field value is null: where <field name> is null
2. The query field value is not Empty syntax: where <field name> is not null

Regarding MySQL query empty fields or non-null fields (is null and not null), this article introduces so much, I hope it will be helpful to everyone, thank you!

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326980600&siteId=291194637