top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between COUNT (), COUNT (*) Functions in SQL?

+2 votes
945 views
What is the difference between COUNT (), COUNT (*) Functions in SQL?
posted Aug 5, 2015 by Archana

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

COUNT(*):

Will count all the rows in the specified table

COUNT(Column Name)

Returns the number of rows which have a value (NULL values will not be counted)

--Or--

Some combinations of Count function in SQL Server and their description.

COUNT(*) returns the number of items in a group. This includes NULL values and duplicates.
COUNT(1) returns the number of items in a group. This includes 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.

For return values greater than 2^31-1, COUNT produces an error. Use COUNT_BIG instead.

This is applicable on below versions of SQL Server

SQL Server 2005
SQL Server 2008 R2
SQL Server 2012
SQL Server 2014

answer Aug 6, 2015 by Manikandan J
...