How do NULLs behave using GROUP BY or DISTINCT?

create table #myTable( bar bit)
go
insert into #mytable values (1)
insert into #mytable values (1)
insert into #mytable values (NULL)
insert into #mytable values (NULL)
go
select distinct bar from #mytable
go
select  bar, count(*) from #mytable group by bar
go 
RESULTS: 
bar  
---- 
NULL
   1 


bar              
---- ----------- 
NULL           2 
   1           2 

Looks like both count/report NULLs correctly.

Comments are closed.

Post Navigation