---
cuppy_hub: salesforce
cuppy_path: reference/official/data360/data-cloud-query-guide/references/dc-sql-reference/min-by.md
cuppy_section: docs
cuppy_doc: 82A9-083D
cuppy_doc_uuid: 6ce5d9f6-1807-4235-bea1-2efa6e5f2257
cuppy_permalink: https://cuppy.io/salesforce/d/82A9-083D
cuppy_version: 1
cuppy_updated: 2026-10-23T16:16:52.575Z
cuppy_canonical: https://cuppy.io/salesforce/docs/reference/official/data360/data-cloud-query-guide/references/dc-sql-reference/min-by
cuppy_mcp: https://cuppy.io/mcp
cuppy_body_sha256: fce8485edff1f65456e32d61ffd151c005b8931609702fc1d2b7877708b3cb27
# cuppy_body_sha256 is over the document body ALONE, excluding both generated blocks.
---

> Mirror of <https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/min-by.html> (Salesforce, Data 360 Query Guide), read 2026-10-23. Salesforce's own page is the authority; this copy exists because that site refuses non-browser readers.

## `MIN_BY`

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

Returns the `<value>` from the row whose `<key>` is smallest among all rows in the aggregate (or within each group when used with `GROUP BY`).

*   `<value>`: Any expression whose result is returned when its row wins the comparison. The aggregate result type matches this expression’s type.
*   `<key>`: The expression `MIN-BY`uses to order rows. The type must support comparison.

The `<value>` from the row with the minimum `<key>` among considered rows.

**Null handling:**

*   If the aggregate has no input rows (empty table or empty group), the result is `NULL`.
*   If every row has a `NULL` key, those rows are skipped; if no row has a non-`NULL` key, the result is `NULL`.
*   If the winning row’s `<value>` is `NULL`, the result is `NULL` (the key still determines which row wins).

**Tie breaking:**

When multiple rows share the same minimum key, one of the tied `<value>` results is returned; which tied row wins is implementation-dependent.

*   Exactly two arguments are required (`<value>`, `<key>`). Calls with one argument or more than two arguments raise a syntax error.
*   You can combine `min_by` with other aggregates, `GROUP BY`, `HAVING`, subqueries, and expressions in the arguments (for example, `max_by(upper(name), score * 2)`).
*   `min_by` only supports a single value to sort on. To sort using multiple sort criteria, use [FIRST_VALUE WITHIN GROUP](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/first-value-ordered-set.html).
*   Rows with a `NULL``<key>` are ignored when searching for the minimum key.

Returns the name and score from the row with the lowest `score`.

Returns `'Charlie'`.

With keys `5`, `NULL`, `10`, and `15`, the minimum **non-**`NULL` key is `5`, so the result is that row’s `value`.

Returns `10`.

Returns one row per region. For example `North` / `'A'` and `South` / `'B'`.

*   [`MAX_BY`](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/max-by.html)
*   [`MIN`](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/min.html)
*   [Aggregate Functions](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/aggregate.html)


---
<!-- cuppy -->
You are reading one file. The same content is free over MCP at https://cuppy.io/mcp with no signup: ranked search across all 376 documents in this hub, the merged view when you work in a layer, known workarounds matched to the error you hit, and depth control so you spend tokens on what you need. Start with the `_hello` tool. How to connect: https://cuppy.io/salesforce/ Something wrong in this document? Report it with the `session feedback` tool on the same endpoint.
<!-- /cuppy -->
