You must Sign In to post a response.
  • Category: SQL Server

    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?
  • #77335
    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
    read this.


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

  • #78283
    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.


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.