Skip to main content

What does the COUNT() aggregate function do?

COUNT() is an aggregate function that counts the number of rows in a dataset.

It can behave differently depending on its argument:

  • COUNT(*) counts all rows, including ones with NULL;
  • COUNT(column_name) counts only rows where the column isn't NULL;
  • COUNT(DISTINCT column_name) counts unique non-empty values.

Example

sql
SELECT COUNT(*) FROM employees;

Returns the total number of employees.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.