Re: How to count NULL columns?
Posted in 1996
Frederic,
You must explicitly test for nulls. By definition, a NULL will
fail all other comparisons. As in your example query:
SELECT COUNT(*) FROM table
WHERE mou_codlet NOT BETWEEN "AAA" and "ZZZ"
since a NULL means "unknown" it isn't known to be outside the "AAA" to
"ZZZ" range so it's excluded from the set. Likewise, the reverse of
your select:
SELECT COUNT(*) FROM table
WHERE mou_codlet BETWEEN "AAA" and "ZZZ"
will also exclude NULL values. (A NULL isn't known to be between
"AAA" and "ZZZ" so it isn't included.)
As you've discovered, if you want to include NULL values in your
select, you must do so explicitly using the "IS NULL" test.
--Craig
On 09 Apr 1996 10:12:35 GMT, Gateway@cornut.fr (Frederic Bouquet)
wrote:
>I tried the following command :
>select count(*) from table where mou_codlet not between "AAA" and "ZZZ">
>but the result returned is not the same as the following sql command
>select count(*) from table where mou_codlet not between "AAA" and "ZZZ" or>mou_codlet is null
>
>Is it normal that the null values are not included in the result of the first
>sql command ?
======================================================================
Craig Kickel | Unix/C/Database Consultant
ckickel@cyberhighway.net | <This space intentionally left blank>
======================================================================