mySql  count function

the mysql count function returns the number of rows that matches a specified criteria.

mysql count(*) function syntax

the count(*) function returns the number of records in a table:

         select    count(*)    from   table_name;

mysql count(column_name) syntax

         select    count(column_name)    from   table_name;

note : the null values will not be counted.

or

mysql count(distinct  column_name) syntax

the count(distinct  column_name) function returns the number of distinct values of the specified column:

         select    count(distinct    column_name)    from   table_name;

this database table use in the below count function example

below is a selection from the "users" table:

useridfirstnamesalarybonus
1sandeep10,0001000
2ankitnull2000
3ram30,0003000
4vikram12,0002000

mysql count function example

to count the all rows in the users table, you use the count(*) function as follows:

               
               select    count(*)    from    users;

the following mysql statement counts the number of bonus column from the users table:

               
               select    count(bonus)    from    users;

the following mysql statement counts the number of unique record column in the 'users' table:

               
               select    count(bonus)    from    users;

note : the return type of the count function is bigint. the count function returns zero if there was no matching row found.