Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

MySQL count()


The MySQL count() function is used to return the count of an expression. It is used when you need to count some records of your table.

Syntax:

  1. SELECT COUNT (aggregate_expression)
  2. FROM table_name
  3. [WHERE conditions];

Parameter explanation

aggregate_expression: It specifies the column or expression whose NON-NULL values will be counted.

table_name: It specifies the tables, from where you want to retrieve records. There must be at least one table listed in the FROM clause.

WHERE conditions: It is optional. It specifies the conditions that must be fulfilled for the records to be selected.

MySQL count() function example

Consider a table named “officers”, having the following data.

mysqlcount1

Execute the following query:

  1. SELECT COUNT(officer_name)
  2. FROM officers;

Output:

mysqlcount2

Here, you can see that that the COUNT function calculates the total number of officers in the table.

 

Comments

comments