Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 count(*) and count(1)

Author  Topic 

manish007
Starting Member

1 Post

Posted - 2004-05-08 : 05:12:05
what is difference between these two ???
if count (1) is the primary key then count(100) will also return value Why ?????

Manish

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-05-09 : 07:43:26
count(1) and count(100) will always return the same value - this basically returns the count of all rows in the table which meet whatever criteria has been specified in your where or join filters - ie exactly what count(*) does.

count all and count distinct have different functionality though.

This is from books online:

COUNT(*) returns the number of items in a group, including NULL values and duplicates.

COUNT(ALL expression) evaluates expression for each row in a group and returns the number of nonnull values.

COUNT(DISTINCT expression) evaluates expression for each row in a group and returns the number of unique, nonnull values.

a lot more can be learned from books online about count and other aggregation.
the best way to understand it better is to experiment with it.



Duane.
Go to Top of Page
   

- Advertisement -