Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: where clause

Re: where clause

From: Jonathan Gennick <jonathan_at_gennick.com>
Date: Fri, 6 Feb 2004 15:26:55 -0500
Message-ID: <18264334978.20040206152655@gennick.com>


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.



Please see the official ORACLE-L FAQ: http://www.orafaq.com

To unsubscribe send email to: oracle-l-request_at_freelists.org put 'unsubscribe' in the subject line.
--

Archives are at http://www.freelists.org/archives/oracle-l/ FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
Received on Fri Feb 06 2004 - 14:26:55 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US