# mode

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [cloud-data-platform-full.txt](https://docs.redpanda.com/cloud-data-platform-full.txt)

---
title: mode
latest-operator-version: v26.1.4
latest-console-tag: v3.7.3
latest-connect-version: 4.93.0
latest-redpanda-tag: v26.1.9
docname: sql/sql-functions/aggregate-functions/ordered-set-aggregate-functions/mode
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: sql/sql-functions/aggregate-functions/ordered-set-aggregate-functions/mode.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-functions/aggregate-functions/ordered-set-aggregate-functions/mode.adoc
description: "`mode()` is an ordered-set aggregate function that returns the most frequently occurring value (the mode) from a set of values."
page-topic-type: reference
page-git-created-date: "2026-05-26"
page-git-modified-date: "2026-05-26"
---

<!-- Source: https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-functions/aggregate-functions/ordered-set-aggregate-functions/mode.md -->

`mode()` is an ordered-set aggregate function that returns the most frequently occurring value (the mode) from a set of values.

## [](#syntax)Syntax

```sql
MODE() WITHIN GROUP (ORDER BY order_list)
```

> 📝 **NOTE**
>
> Null values are ignored during the calculation. If `NULL` is the most frequent value, the function returns the second most common value.

## [](#parameters)Parameters

-   `()`: This function does not take any arguments, but the parentheses are required.


## [](#examples)Examples

The following example uses a simplified version of the `film` table from the [Pagila database](https://www.postgresql.org/ftp/projects/pgFoundry/dbsamples/pagila/pagila/), containing only the `title`, `length` and `rating` columns.

```sql
DROP TABLE IF EXISTS film;
CREATE TABLE film (
  title text NOT NULL,
  length int,
  rating text
);
INSERT INTO film(title, length, rating) VALUES
  ('ATTRACTION NEWTON', 83, 'PG-13'),
  ('CHRISTMAS MOONSHINE', 150, 'NC-17'),
  ('DANGEROUS UPTOWN', 121, 'PG'),
  ('KILL BROTHERHOOD', 54, 'G'),
  ('HALLOWEEN NUTS', 47, 'PG-13'),
  ('HOURS RAGE', 122, 'NC-17'),
  ('PIANIST OUTFIELD', 136, 'NC-17'),
  ('PICKUP DRIVING', 77, 'G'),
  ('INDEPENDENCE HOTEL', 157, 'NC-17'),
  ('PRIVATE DROP', 106, 'PG'),
  ('SAINTS BRIDE', 125, 'G'),
  ('FOREVER CANDIDATE', 131, 'NC-17'),
  ('MILLION ACE', 142, 'PG-13'),
  ('SLEEPY JAPANESE', 137, 'PG'),
  ('WRATH MILE', 176, 'NC-17'),
  ('YOUTH KICK', 179, 'NC-17'),
  ('CLOCKWORK PARADISE', 143, 'PG-13');
```

The following query retrieves the most frequent ratings found in the film table:

```sql
SELECT MODE()
  WITHIN GROUP (ORDER BY rating)
FROM film;
```

The query returns:

```sql
| mode  |
|-------|
| NC-17 |
```