May 14, 2009 at 2:52 am
What is the difference between Count(*),Count(1).... in sql server
?
for ex. A table contains 100
select count(*) from emp
select count(1) from emp
select count(2) from emp
All the three queries display the same result .then what is the difference between them?
Tanx 😀
May 14, 2009 at 3:47 am
No practical difference. They both count the number of rows in the resultset.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
May 14, 2009 at 4:06 am
select count(*) from table
and
select count(1) from table
will return the same results, but
select count(column name) from table
will return the number of non null columns
May 14, 2009 at 4:56 am
SeanF (5/14/2009)
select count(column name) from tablewill return the number of non null columns
More correctly it will return the number of rows in the table where the column specified is not null.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply