# for_min

> 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: for_min
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/for-min
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/for-min.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-functions/aggregate-functions/for-min.adoc
description: The `for_min()` function searches for a minimum in a specific column and returns a value related to that minimum from another column.
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/for-min.md -->

The `for_min()` function searches for a minimum in a specific column and returns a value related to that minimum from another column.

## [](#syntax)Syntax

```sql
FOR_MIN(metric, value)
```

## [](#arguments)Arguments

-   `metric`: Must be one of the following data types: `int`, `long`, `float`, `double`, `date` or `timestamp`.

-   `value`: Can be any data type except `text`.


The `for_min()` function returns `NULL` in the following situations:

-   There are no input rows

-   The `metric` column contains only `NULL` values

-   The `value` corresponding to the metric minimum value is `NULL`


This function also returns `NaN` (not-a-number) if the input contains a `NaN`.

## [](#examples)Examples

The following examples use a `payments` table that stores customer payment records, including any applied discounts:

```sql
CREATE TABLE payments (
  paymentid int,
  customer_name text,
  price real,
  discount real);

INSERT INTO
  payments (paymentid, customer_name, price, discount)
VALUES
  (1, 'Alex', 280.12, 0.1),
  (2, NULL, 35.75, NULL),
  (3, 'Alex', 45.1, 0.05),
  (4, 'Alex', NULL, 0.4),
  (5, 'John', NULL, 0.1),
  (6, 'Bob', 50.45, 0.07),
  (7, 'Bob', 120.5, 0.0);
```

To view the `payments` table content, run the query:

```sql
SELECT * FROM payments;
```

```sql
 paymentid | customer_name | price  | discount
-----------+---------------+--------+----------
         1 | Alex          | 280.12 |      0.1
         2 |               |  35.75 |
         3 | Alex          |   45.1 |     0.05
         4 | Alex          |        |      0.4
         5 | John          |        |      0.1
         6 | Bob           |  50.45 |     0.07
         7 | Bob           |  120.5 |        0
(7 rows)
```

### [](#for_min-basic-usage)`for_min()` basic usage

To determine the price associated with the lowest discount applied across all payments, run the query:

```sql
SELECT FOR_MIN(discount, price) AS for_lowest_discount FROM payments;
```

The query returns the following output:

```sql
 for_lowest_discount
---------------------
               120.5
(1 row)
```

### [](#for_min-with-group-by-clause)`for_min()` with `GROUP BY` clause

To determine the discount associated with the lowest price paid by each customer, use the `GROUP BY` clause with the `for_min()` function:

```sql
SELECT customer_name,
  FOR_MIN(price, discount) AS discount
FROM payments
GROUP BY customer_name;
```

This query returns the following output:

```sql
customer_name | discount
---------------+----------
 Bob           |     0.07
 Alex          |     0.05
               |
 John          |
(4 rows)
```