You must Sign In to post a response.

What is the difference between Count(*),Count(1).... in sql server?

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?


Comments

Author: Cema Indumathy V15 Sep 2006 Member Level: Gold   Points : 2

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. expression - Is an expression of any type except uniqueidentifier, text, image, or ntext. Aggregate functions and subqueries are not permitted.

Author: Rajaraman15 Sep 2006 Member Level: Gold   Points : 2

read this.


http://www.techonthenet.com/sql/count.php

Author: G V Balasubramanyam18 Sep 2006 Member Level: Bronze   Points : 2

count(*):It counts the number of rows in a table.

count(Column_name):It counts no of values in column but ignores null values.

count(distinct column_name):It counts the no of values in column but ignores duplicates values and null values.