When we want to query all result sets in SQL for which a column value is NULL, the query condition should write like this
SELECT * FROM table where field is null
Instead, use the SELECT * from table where field = NULL to not find the correct result. Then why is this? To understand why, you need to know the three-valued logic in SQL.
possible values for logical expressions in SQL include True, false, and unknown, which are called three-valued logic .
We know that in other languages, there are only two types of logical expressions, either True or false. In SQL, there is a third logical expression, unknown, which is unique in SQL. From the literal meaning we can solve the meaning of the deserve value is: What do not know, is nothing. In general, when we compare any value (including null itself) to NULL, we will return unknown. In query expressions, such as where and have, unknown is considered false. So we figured out why the select * from table where field =null couldn't find the correct result.
But not all unknown will be treated as false, and in a check constraint, unknown is treated as true. This is why we can also insert a null value into the field if we set the value of a field to be greater than or equal to 0, because the logical result of null>=0 in the check constraint is unknown treated as true.
It is important to note that in the grouping clause and the sort clause, SQL sees null as equal
That
1, groupby Will divide all null values into a group .
2,Order by will arrange all the null values together .
Go
SQL =null Query results and is null to query the result description