Quick Contact

    COUNT Function

    In this tutorial, we will understand in detail the aggregate function Count inSQL. Let us now try to learn more about the count function with examples.

    What are the Aggregate Functions in SQL?

    Aggregate functions are used over a set of values, which in return comes down to a single value.

    Count function in SQL is deterministic in nature i.e. no matter how many times it is run, the answer remains the same until the contents of the table are modified.

    Count function doesn’t ignore the NULL values in the database and considers them too while calculating the result of the query.

    In SQL we have various Aggregate functions like:

    Sr.No Function Description
    1 AVG() Returns the average value.
    2 COUNT() Returns the count.
    3 MAX() Returns the maximum out of the given values.
    4 MIN() Returns the minimum out of the given values.
    5 SUM() Returns the sum of the given values.
    6 VAR() Returns variance of the given values.

    Where do we use Count in SQL?

    We use the count function when we need to get the count of something. For example:

    1. COUNT(*):

      Returns the total records in the table.

      Syntax:

      SELECT col1,

      Col2, COUNT(*) AS col_count,

      FROM tableName;

    2. COUNT(columnName):

      Returns the total number of records(Includes the Null values also) in the columnName.

      Syntax:

      SELECT col1,col2,…….,

      COUNT(colName) AS col_count

      FROM tableName;

    3. COUNT(DISTINCT columnName):

      Returns the count of unique records in the columnName.

      Syntax:

      SELECT col1,col2,….,

      COUNT(DISTINCT colName) AS colDistinctCount

      FROM tableName;


    Copyright 1999- Ducat Creative, All rights reserved.

    Anda bisa mendapatkan server slot online resmi dan terpercaya tentu saja di sini. Sebagai salah satu provider yang menyediakan banyak pilihan permainan.