Beginner

381. COUNT Function

Learn how to count rows and values in SQL.

📘 Lesson 381 of 728 ⏱ 9 min 🎯 Beginner

COUNT is an aggregate function used to count rows or non-NULL values in a result set.

Counting records is one of the most common analytical requirements, from customer counts to transaction volumes.

Count the total number of employees.

SQL
SELECT
    COUNT(*) AS TotalEmployees
FROM Employees;

COUNT is used for customer counts, transaction volumes, employee headcount, order analysis, and operational reporting.

  • COUNT is an aggregate function.
  • COUNT(*) counts rows.
  • COUNT(column) counts non-NULL values.
  • COUNT can be combined with GROUP BY.
  • COUNT is widely used in data analysis.
What does COUNT(*) do?

COUNT(*) counts the number of rows returned by the query.

Does COUNT(column) count NULL values?

No. COUNT(column) counts only non-NULL values in that column.

Have you finished this lesson?

Introduction to SQL – All Lessons