# LEAST

> 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: LEAST
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/math-functions/least
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: sql/sql-functions/math-functions/least.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-functions/math-functions/least.adoc
description: The `LEAST` function returns the smallest value in a list 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/math-functions/least.md -->

The `LEAST` function returns the least or smallest value in a list of values. It needs at least one argument to work with. If different types are mixed, like a text and a number, it returns an error.

For example, comparing the greatest value among 4, “two”, and 9 would result in an error.

## [](#syntax)Syntax

The syntax for the `LEAST` function is:

```sql
LEAST(value_1, [value_n])
```

Where:

-   `value_1`: Represents the first value.

-   `value_n`: Represents one or more additional values, separated by commas.


> 📝 **NOTE**
>
> **Info:** \* `NULL` values in the list are ignored. - The result will be `NULL` if all the expressions evaluate to `NULL`.

## [](#examples)Examples

These examples show how to use the `LEAST` function:

### [](#basic-usage)Basic usage

Consider the example:

```sql
SELECT LEAST(3,5,8,9,10);
```

The query will return `3`, the smallest value among the provided values.

```sql
 least
-------
     3
```

### [](#string-comparison)String comparison

String comparison is also supported:

```sql
SELECT LEAST('a','b','c','aa');
```

In this case, the result will be `'a'`, as it is the smallest string.

```sql
 least
-------
     a
```

### [](#handle-null-values)Handle NULL values

`NULL` values are ignored when determining the smallest value:

```sql
SELECT LEAST (5,null,9);
```

The result will be the smallest non-NULL value, which is `5`.

```sql
 least
-------
     5
```

### [](#negative-numbers)Negative numbers

Negative numbers can also be compared:

```sql
SELECT LEAST (4,-4,-8,8);
```

This query will return `-8`, the smallest value among the provided numbers.

```sql
 least
-------
    -8
```

### [](#use-table-data)Use table data

Suppose there is a table named `grades` containing columns `x`, `y`, and `z`.

```sql
CREATE TABLE grades (
    name TEXT,
    x INT,
    y INT,
    z INT
);

INSERT INTO grades (name, x, y, z)
VALUES
    ('Jane', 50, 0, 70),
    ('Rio', 60, 30, 80),
    ('John', 60, 60, 86),
    ('Rose', 80, 90, 88),
    ('Gary', 100, 80, 90);
```

To find the smallest value among these columns, use the query:

```sql
SELECT *, LEAST(x, y, z) AS least_grade FROM grades;
```

This query will add a new column named `least_grade` to the result, displaying the smallest value among columns `x`, `y`, and `z`.

```sql
 name |  x  | y  | z  | least_grade
------+-----+----+----+-------------
 Jane |  50 |  0 | 70 |           0
 Rio  |  60 | 30 | 80 |          30
 John |  60 | 60 | 86 |          60
 Rose |  80 | 90 | 88 |          80
 Gary | 100 | 80 | 90 |          80
```