The database is mysql5.7

Found the problem

A field in the database is null before and needs to be added as a query condition. When = is used for query, no data is available

The hypothesis table is shown as follows:

The query

SELECT * from tb_kjkm t WHERE t.unitType = null; 
Copy the code

SELECT * from tb_kjkm t WHERE t.unitType is null;
Copy the code

If the query condition is = NULL, data cannot be queried. If is NULL is used, data can be queried normally

SQL = null and is NULL

Normal language logical expressions have only true and false. Possible values for logical expressions in SQL include TRUE, FALSE, and UNKNOWN. They are called three-valued logic, and three-valued logic is unique to SQL. A NULL value typically represents a missing or irrelevant value. When a lost value is compared to another value (which may also be NULL), the logical result is always UNKNOWN. NOT TRUE equals FALSE, NOT FALSE equals TRUE, and the negative UNKNOWN is UNKNOWN. UNKNOWN logical results and NULL are treated differently in different language elements. In query expressions such as where, Having, and on, UnKnown is treated as false. In the check constraint, UnKnown is treated as true. If the value of a field must be greater than or equal to 0, we can also insert Null values into the field

Note that SQL treats NULL as equal in grouping and sorting clauses, i.e. : 1. GROUP BY groups all null values into one GROUP. 2, ORDER BY will arrange all NULL values together.

summary

1. For conditional query, = NULL or! Cannot be used. =null For comparison, you must use is NULL /not null 2. When grouping sort, null is considered equal to a group