Subject | Why does SUM() return null? |
---|---|
Author | rogervellacott |
Post date | 2002-02-18T17:35:33Z |
The query SELECT SUM(NUMERIC_FIELD_X) FROM TABLE_X WHERE ... returns
NULL if no records are found. Both logic and intuition suggest that
it should return zero. If there are no records, then the total is
zero. It is not "unknown".
It means that an update query such as
UPDATE TABLE_X SET FIELD_X = FIELD_X + (SELECT SUM( etc.....
not only fails, but also loses the original value of FIELD_X.
This seems very dangerous to me. Is it as intended? Does it conform
to SQL standards? Can it be changed in a future release?
NULL if no records are found. Both logic and intuition suggest that
it should return zero. If there are no records, then the total is
zero. It is not "unknown".
It means that an update query such as
UPDATE TABLE_X SET FIELD_X = FIELD_X + (SELECT SUM( etc.....
not only fails, but also loses the original value of FIELD_X.
This seems very dangerous to me. Is it as intended? Does it conform
to SQL standards? Can it be changed in a future release?