The COUNT function returns the number of rows or non-null values that match a query. COUNT(*) counts rows, while COUNT(column_name) counts non-null values in the specified column.
Counting records is one of the most common analytical tasks. Analysts use COUNT to measure customers, employees, transactions, orders, products, and other business records.
A manager wants to know how many employees are currently stored in the Employees table. COUNT(*) can return the total number of employee records.
SELECT
COUNT(*) AS TotalEmployees
FROM Employees;
COUNT is widely used in customer analysis, transaction reporting, sales analysis, employee reporting, operational dashboards, and business metrics.
- COUNT is an aggregate function.
- COUNT(*) counts rows.
- COUNT(column_name) ignores NULL values.
- COUNT can be combined with GROUP BY.
- COUNT is commonly used in business reporting.
What does COUNT(*) return?
COUNT(*) returns the number of rows in the result set.
What is the difference between COUNT(*) and COUNT(column)?
COUNT(*) counts rows, while COUNT(column) counts only non-null values in that column.