MySQL Wildcards

MySQL Wildcards

MySQL Aliases

MySQL Aliases

MySQL Data Types

MySQL Data Types

MySQL Interview Questions

MySQL Interview Questions and Answers


MySQL count() Function

The MySQL count() function returns the number of rows that matches a specified expression. It is used when you need to count number of rows in atable or number of records of your table.

MySQL COUNT FUNCTION Syntax

To count or calculate number of rows in a table, use the following syntax:

Syntax

SELECT COUNT(col1) 
FROM tablename
WHERE condition;

Parameters:

tablename: The table name from which you want to fetch records.

col1: The column on which you want to perform count. It will count NON-NULL values.

MySQL COUNT FUNCTION example

The following MySQL, calculate the total number of "firstName" in the "tblCustomerLoan" table:

Example

SELECT COUNT(firstName) FROM tblCustomerLoan;

OR

SELECT COUNT(*) AS count FROM tblCustomerLoan;

Note:

In the above example, we are calculating the number of "firstName" from tblCustomerLoan" table.

You can use MySQL Command Line Client to count number of rows in the specified table. It will look like this: