# `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](/docs/data/data-cloud-query-guide/references/dc-sql-reference/approx-count-distinct.md)
- [SUM](/docs/data/data-cloud-query-guide/references/dc-sql-reference/sum.md)
- [Aggregate Functions](/docs/data/data-cloud-query-guide/references/dc-sql-reference/aggregate.md)
