`GREATEST` and `LEAST`
Data 360 Query Guide, mirrored from developer.salesforce.com: **Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API
markdownreferencev13QB7-63VRguide: data-cloud-query-guidestage: referencetrust: officialsource: developer.salesforce.comservice: data360interface: sql`GREATEST` and `LEAST`Data 360Data CloudData 360 Query Guide
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: IncludesNULLvalues 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.
GREATESTandLEASTcompare values across the arguments within a single row. To find the largest or smallest value down a column across rows, use the aggregate functionsMAXandMIN.
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.