The COUNT() function returns the number of rows that matches a specified criteria.
The COUNT(column_name) function returns the number of values (NULL values will not be counted) of the specified column:
The COUNT(*) function returns the number of records in a table:
The COUNT(DISTINCT column_name) function returns the number of distinct values of the specified column:
Note: COUNT(DISTINCT) works with ORACLE and Microsoft SQL Server, but not with Microsoft Access.
We have the following "Purchases" table:
Now we want to count the number of Purchases from "Customer Tendulkar".
We use the following SQL statement:
The result of the SQL statement above will be 2, because the customer Tendulkar has made 2 Purchases in total:
If we omit the WHERE clause, like this:
The result-set will look like this:
which is the total number of rows in the table.
Now we want to count the number of unique customers in the "Purchases" table.
which is the number of unique customers (Karmen, Tendulkar, and Jensen) in the "Purchases" table.
Your Query was successfully sent!