How do NULLs behave using GROUP BY or DISTINCT?

by John 2. October 2008 01:23
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.
Tags:
Categories: SQL

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading