Home  >  Article  >  Database  >  How to query null value in mysql

How to query null value in mysql

WBOY
WBOYOriginal
2022-05-26 18:13:2313708browse

In mysql, you can use the SELECT statement with the IS NULL keyword to query for null values. The IS NULL keyword is used to determine whether the field value is a null value. If the field value is a null value, it is displayed in In the result, the syntax is "SELECT * FROM table name WHERE field name IS NULL;".

How to query null value in mysql

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How to query null values ​​in mysql

MySQL provides the IS NULL keyword to determine whether the value of a field is NULL. The null value is different from 0, which is also different from the empty string.

If the value of the field is null, the query conditions are met and the record will be queried. If the value of the field is not null, the query condition is not met.

The basic syntax format for using IS NULL is as follows:

IS [NOT] NULL

Among them, "NOT" is an optional parameter, indicating that the condition is met when the field value is not a null value.

Example 1

The following uses the IS NULL keyword to query the records whose login_date field is NULL in the tb_students_info table.

How to query null value in mysql

Note: IS NULL is a whole, IS cannot be replaced with "=". If you replace IS with "=", no results will be retrieved, and the database system will display a prompt such as "Empty set (0.00 sec)". Similarly, IS NOT in IS NOT NULL cannot be replaced with "!=" or "".

IS NOT NULL means querying records whose field value is not empty.

Example 2

The following uses the IS NOT NULL keyword to query the records where the login_date field in the tb_students_info table is not empty.

How to query null value in mysql

Recommended learning: mysql video tutorial

The above is the detailed content of How to query null value in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn