Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Reg: Count, Distinct & NULL

915396Sep 15 2014 — edited Sep 16 2014

Hi Experts,

It is late night (or morning!) here, I'm almost drowsy, and not getting this simple query behavior.

with t as (

  select 1 val from dual union all

  select 1 from dual union all

  select 2 from dual union all

  select null from dual union all

  select null from dual union all

  select null from dual

)

--------

select count(distinct val) from t; -->-- 2 records

But, why this query gives 3 records and includes the NULL value:

select count(*) from (select distinct val from t);  -->-- 3 records

and

select count(val) from (select distinct val from t);  -->-- 2 records

What am I missing. Any pointers?

Version: Oracle 11.2.0.4.0

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 14 2014
Added on Sep 15 2014
5 comments
2,275 views