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

# NULLIF

> Returns NULL when two values are equal, otherwise returns the first value.

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

NULLIF(NULL, x) is NULL. NULLIF(x, NULL) returns x when x is not NULL; both NULL inputs return NULL.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
nullif(value, other)
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| value | BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY or STRUCT | Yes | Value to return unless it matches other. For DECIMAL(p, s), p is precision (total digits) and s is scale (digits after the decimal point). |
| other | BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY or STRUCT | Yes | Value to compare against value. 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). |

## Returns

* Type: Same SQL type as value
* Possible values: The first argument value or NULL.
* NULL behavior: NULLIF(NULL, x) is NULL. NULLIF(x, NULL) returns x when x is not NULL; both NULL inputs return NULL.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Yes |

## Usage notes

* Comparison operands may be converted, but the result preserves the first argument type.
* 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 nullif(7, 7) AS equal_value, nullif(7, CAST(NULL AS INT)) AS null_other;
```

| equal\_value | null\_other |
| - | - |
| NULL | 7 |

### Replace a sentinel string with NULL

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT nullif('unknown', 'unknown') AS missing, nullif('red', 'unknown') AS present;
```

| missing | present |
| - | - |
| NULL | red |

## Related functions

* [coalesce](/query/sql/functions/conditional/coalesce)
* [equal\_null](/query/sql/functions/conditional/equal_null)


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