---
title: nullif function
description: Learn the syntax of the nullif function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/nullif
---

# `nullif` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Returns `NULL` if `expr1` equals `expr2`, or `expr1` otherwise.

## Syntax

```
nullif(expr1, expr2)
```

## Arguments

* `expr1`: An expression of any type.
* `expr2`: An expression of the same type as `expr`.

## Returns

`NULL` if `expr1` equals to `expr2`, or `expr1` otherwise.

## Examples

```sql
> SELECT nullif(2, 2);
 NULL

> SELECT nullif(2, 3);
 2
```

## Related functions

* [`coalesce` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/coalesce.md)
* [`decode` (key) function](https://docs.databricks.com/aws/en/sql/language-manual/functions/decode.md)
* [`case` expression](https://docs.databricks.com/aws/en/sql/language-manual/functions/case.md)
