# `MODE`

**Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API

Returns the most frequent input value. If there are multiple equally frequent values, returns an arbitrary one.

## Syntax

```sql
mode() WITHIN GROUP (ORDER BY <sort_expression>)
```

## Arguments

### Required

- `<sort_expression>`: An expression of any sortable type that determines the value to find the mode of.

## Returns

Returns the same type as the sort expression. Returns NULL if no rows are selected.

## Considerations

- This is an ordered-set aggregate function.
- NULL values in the sorted input are ignored.
- When multiple values have the same highest frequency, the choice between them is arbitrary.

## Examples

### Find Most Common Value

Get the most frequently occurring category.

```sql
SELECT mode() WITHIN GROUP (ORDER BY category) AS most_common_category
FROM products;
```

### Mode by Group

Find the most common value for each group.

```sql
SELECT region, mode() WITHIN GROUP (ORDER BY product_type) AS popular_product
FROM sales
GROUP BY region;
```

## Related Documentation

- [PERCENTILE_CONT](/docs/data/data-cloud-query-guide/references/dc-sql-reference/percentile-cont.md)
- [PERCENTILE_DISC](/docs/data/data-cloud-query-guide/references/dc-sql-reference/percentile-disc.md)
- [Aggregate Functions](/docs/data/data-cloud-query-guide/references/dc-sql-reference/aggregate.md)
