---
schema_version: "1"
id: bf9837ac1320764e997ddc88087125c4fe7940cfa6ee03f08a60bae7b236b510
title: MODE
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/mode.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/mode.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 183cbd284285303d8680841ec51ab4766511cbbc29107e17b3f0f9070b1e74dc
products:
  - Data 360 Query Guide
  - Data 360 Developer Documentation
---
# `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](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/percentile-cont.md)
- [PERCENTILE_DISC](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/percentile-disc.md)
- [Aggregate Functions](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/aggregate.md)
