Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: where clause
DB> I found following results that I don't understand.
Ok.
SQL>> SELECT COUNT(*) FROM test;
This counts rows. Nullity isn't an issue, since a "row" cannot be null. Only columns may be null. You may know that already.
SQL>> SELECT COUNT(*) FROM test WHERE status_flag !='A';
DB> COUNT(*) DB> ---------- DB> 38
DB> I thought the last query should return 1676 (status_flag ='S' + status_flag DB> is null) instead of 38 (status_flag ='S' only). Any ideas???
The above query will not count NULL status_flag values. That's because NULL is not the same as !='A'.
The thing I like to show people is to issue a query like the following:
SELECT *
FROM test
WHERE status_flag = 'A'
OR status_flag != 'A';
At first glance, you might think this query would return *all* rows in the table. However, it won't. Rows with NULL status_flag values will not satisfy either condition. It's a bit counterintuitive. That's the joy of working with three-valued logic.
Best regards,
Jonathan Gennick --- Brighten the corner where you are http://Gennick.com * 906.387.1698 * mailto:jonathan@gennick.com
Join the Oracle-article list and receive one article on Oracle technologies per month by email. To join, visit http://four.pairlist.net/mailman/listinfo/oracle-article, or send email to Oracle-article-request_at_gennick.com and include the word "subscribe" in either the subject or body.
![]() |
![]() |