> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# GREATEST

> Returns the greatest value among compatible arguments.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

In Databricks context NULL arguments are ignored unless all arguments are NULL. In the Snowflake-style/default context, any NULL argument yields NULL.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
greatest(value1 [, value2 ...])
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| value1 | BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY or STRUCT | Yes | First value to compare. For DECIMAL(p, s), p is precision (total digits) and s is scale (digits after the decimal point). |
| value2 | BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY or STRUCT | No | Further values to compare. Must convert to the same SQL type as the other arguments in this comparison or result branch. Use explicit CAST when mixing types. For DECIMAL(p, s), p is precision (total digits) and s is scale (digits after the decimal point). This argument can repeat. |

## Returns

* Type: The common comparison type after converting the arguments; explicit same-type arguments preserve that SQL type
* Possible values: One of the argument values after applicable type conversion, or NULL.
* NULL behavior: In Databricks context NULL arguments are ignored unless all arguments are NULL. In the Snowflake-style/default context, any NULL argument yields NULL.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Partial (Value comparison is deterministic, but common-type/numeric conversions may alter representation.) |

## Usage notes

* INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
* Query tools may report a DECIMAL result as DOUBLE or a TIME result as INTEGER. The returned value still keeps its decimal precision and scale, or its time type. A reported type does not convert the value.
* Deterministic: The same inputs and settings produce the same result.

## Examples

### Typical behavior

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT greatest(2, 7, 3) AS "value";
```

| value |
| - |
| 7 |

### Compare dates

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT greatest(DATE '2024-01-01', DATE '2024-03-01') AS latest_date;
```

| latest\_date |
| - |
| 2024-03-01 |

## Related functions

* [least](/query/sql/functions/conditional/least)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.