> ## 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.

# COALESCE

> Returns the first non-NULL value from its arguments.

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

Returns NULL when every argument is NULL.

## Syntax

### Scalar

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

* All result alternatives must have compatible types. Matching types are preserved; mixed types may be converted to a common type. Use explicit casts to choose the result type.

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| value1 | BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY, MAP or STRUCT | Yes | First value to inspect. 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, MAP or STRUCT | No | Further values inspected in order. 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: Common SQL type after conversion of its arguments
* NULL behavior: Returns NULL when every argument is NULL.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Partial (Selection is exact; implicit casts to a common type may alter values.) |

## Usage notes

* A single argument returns that argument. At least one argument is required.
* 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 coalesce(CAST(NULL AS INT), 5, 8) AS "value", coalesce(CAST(NULL AS INT), CAST(NULL AS INT)) AS all_null;
```

| value | all\_null |
| - | - |
| 5 | NULL |

### Choose the first available string

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT coalesce(CAST(NULL AS VARCHAR), 'unknown', 'unused') AS chosen;
```

| chosen |
| - |
| unknown |

## Related functions

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


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