Once more about NULL values page 2 |
||||||||||||||||||||||||||||||||||||
For example, let's consider the information about the models 1298 in the Laptop table. Let's carry out the query to learn the data: Here are the results of carrying out of this query:
Let's consider the task of getting the average price of the model 1298. While all prices are known the solution of this task doesn't cause any doubts:
Let now the price of the model with code 4 is unknown. If, as it was decided earlier, we substitute an unknown value, say, with zero (UPDATE laptop SET price=0 WHERE code=4), then we will get knowingly the wrong average price value – 550.0. If we use the NULL value, the result will be quite right – 825.0, because null values will be ignored under grouping, in the result of which the average value will be calculated only by the models with the known price (that is the average value by two models). So, as I tried to show, the NULL value is the inherent peculiarity of the relational model, and instead of critics I offer to learn correctly working with such values.
Notes:
For the sake of objectivity we recommend you to read the reasonable criticism by C.J. Date concerning use of NULL values [1]. E.F. Codd [6] has offered two different types of the NULL values corresponding to just those two aspects of their applying about which there was a speech above. |