---
schema_version: "1"
id: 637b8d8f7f840634795321720ccf4ee09d412cb31ade31dd9f97f2624393d619
title: COUNT
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/data-cloud-query-guide/references/data-cloud-sql-reference/aggregate-func/count.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/count.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 7cfa27614b14d3bf35f40ca72bf5f360b2d17892eaa8e7ab65ab58de8c13fd8d
products:
  - Data 360 Query Guide
  - Data 360 Developer Documentation
---
# `COUNT`

**Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API

Counts the number of input rows or non-null values.

## Syntax

```sql
count(*)
count(<expression>)
count(DISTINCT <expression>)
```

## Arguments

### Required

- `*`: Counts all rows, including rows with NULL values.
- `<expression>`: Counts rows where the expression is not NULL.

### Optional

- `DISTINCT`: Counts only distinct non-null values.

## Returns

Returns a `bigint` representing the count.

## Considerations

- Unlike other aggregates, `count` returns 0 (not NULL) for empty sets.

## Examples

### Count All Rows

Count the total number of rows.

```sql
SELECT count(*) AS total_orders
FROM orders;
```

### Count Non-NULL Values

Count the rows with non-null values.

```sql
SELECT count(email) AS customers_with_email
FROM customers;
```

### Count Distinct Values

Count the unique values.

```sql
SELECT count(DISTINCT category) AS category_count
FROM products;
```

### Count by Group

Count the rows per group.

```sql
SELECT department, count(*) AS employee_count
FROM employees
GROUP BY department;
```

## Related Documentation

- [APPROX_COUNT_DISTINCT](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/approx-count-distinct.md)
- [SUM](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/sum.md)
- [Aggregate Functions](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/aggregate.md)
