Tuesday, 4 October 2011

What is the difference between select count(*) and select count(any_column)?

  • COUNT(*) will include NULLS
  • COUNT(column_name) will not include NULLS.
Example :
create table myTable (id int,name nvarchar(100))
insert into myTable values(1,null)
insert into myTable values(null,'Hello')
insert into myTable values(null,null)

select COUNT(*) from myTable
Result : 3
select COUNT(name) from myTable
Result : 1

No comments:

Post a Comment