MS Access Count() Function
The Count()
function in MS Access is used to count the number of records (rows) in a table that meet specified criteria or the number of non-null values in a particular column.
Count(): Definition and Usage
Count()
is an aggregate function; it summarizes data from multiple rows to give a single result. It's extremely useful for getting totals, determining the size of datasets, or performing calculations based on the number of rows. Count()
ignores NULL
values.
Syntax
Syntax
Count(expression)
Parameter Values
Parameter | Description |
---|---|
expression |
A field name (column) or a string value. If you use a field name, it counts the number of non-null values in that column. If you use a string value (like `"*"`), it counts the total number of rows, regardless of whether the column is null or not. This is required. |
Example
Counting Products
This example counts the number of products in the 'Products' table (assuming a table named 'Products' exists with a 'ProductID' column). Using `"*"` as the expression counts all rows, even those with null `ProductID`.
Syntax
SELECT Count(ProductID) AS NumberOfProducts FROM Products;
Output
NumberOfProducts
----------------
(The number of products in the Products table)