Once more about NULL values page 3 |
|||||||
Comparison of the rows containing NULLsIt is well known that a predicate is evaluated as UNKNOWN when using the comparison with NULL, i.e. neither TRUE nor FALSE. So It is not surprising that when comparing NULLs with each other, these are considered equal in some cases, and not equal in other ones. Let's go to examples. Begin with joining of two similar rows containing NULLs on equality of all the columns.
Only those rows will be concatenated which the predicate is evaluated as TRUE for. In our example the predicate is UNKNOWN, so we do not get any rows. Nevertheless the intersection of the queries (as well as uniting and exception) consider these rows identical.
It can be concluded that NULL-values are not considered equal (nor nonequal also) in horizontal operations, but equal in vertical operations. In particular, when grouping by column including NULLs, the latter ones form one group. Finally let's consider a few solutions to the problem of determining the number of printers with unknown prices. The PrinterN table differs from the Printer table in that the couple of prices is set in NULL. (1) Substraction of number of rows with known price from total number of rows. (2) Using IS NULL predicate to calculate number of NULLs in price column. (3) Grouping by price with taking the group formed by unknown price.
|