Forums » .NET » SQL Server »

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


Posted Date: 15 Sep 2006      Posted By:: Monisha Profile photo    Member Level: Gold    Member Rank: 967     Points: 2   Responses: 3



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?





Responses

#77335    Author: Cema Indumathy V      Member Level: Gold      Member Rank: 249     Date: 15/Sep/2006   Rating: 2 out of 52 out of 5     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.

 
#77497    Author: Rajaraman      Member Level: Gold      Member Rank: 79     Date: 15/Sep/2006   Rating: 2 out of 52 out of 5     Points: 2

read this.


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


 
#78283    Author: G V Balasubramanyam      Member Level: Bronze      Member Rank: 0     Date: 18/Sep/2006   Rating: 2 out of 52 out of 5     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.





 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : how to get 5 th to 10 th records in sql server
Previous : can we use truncate statement in trigger?
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages

Subscribe to Subscribers
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India