How to query records with null values in MySQL?
If you want to search for records with empty values in a MySQL database, you can use the IS NULL operator or the IS NOT NULL operator. Here are examples of both ways to query.
- Use the IS NULL operator to query for records with empty values.
SELECT * FROM 表名 WHERE 列名 IS NULL;
For example, to search for records in the table named “students” with empty values for age:
SELECT * FROM students WHERE age IS NULL;
- Query records that are not empty using the IS NOT NULL operator.
SELECT * FROM 表名 WHERE 列名 IS NOT NULL;
For example, to retrieve records from a table named “students” where the age is not empty:
SELECT * FROM students WHERE age IS NOT NULL;
Please note: The “table name” and “column name” in the example above need to be replaced with the actual table name and column name.