---
cuppy_hub: salesforce
cuppy_path: reference/official/data360/data-cloud-query-guide/references/dc-sql-reference/greatest-least.md
cuppy_section: docs
cuppy_doc: 3QB7-63VR
cuppy_doc_uuid: 50a3313b-8f0f-496e-ab4d-07db469f81e1
cuppy_permalink: https://cuppy.io/salesforce/d/3QB7-63VR
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/greatest-least
cuppy_mcp: https://cuppy.io/mcp
cuppy_body_sha256: f88024a8db14e580ba54180f197b2328bd23669ba61eed746fe4f3dcd010c191
# 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/greatest-least.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.

## `GREATEST` and `LEAST`

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

Returns the largest or smallest value from a list of expressions.

*   `<value>`: An expression to evaluate. Provide two or more arguments. All arguments must be convertible to a common data type, which is the type of the result.

*   `PRESERVE NULLS`: Includes `NULL` values in the comparison instead of ignoring them.

`GREATEST` returns the largest value from the list. `LEAST` returns the smallest value from the list. The result uses the common data type of the arguments.

By default, `GREATEST` and `LEAST` ignore `NULL` values in the list; the result is `NULL` only if all inputs evaluate to `NULL`. When `PRESERVE NULLS` is specified, the result is `NULL` if any input is `NULL`.

*   `GREATEST` and `LEAST` compare values across the arguments within a single row. To find the largest or smallest value down a column across rows, use the aggregate functions `MAX` and `MIN`.

Return the largest of several numeric values.

Returns `7`.

Return the smallest of several numeric values.

Returns `2`.

Return `NULL` when any input is `NULL`.

Returns `NULL` because a `NULL` input is present.

*   [COALESCE](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/coalesce.html)
*   [Conditional Expressions](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/conditional-func.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 -->
