# NULLIF

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [cloud-data-platform-full.txt](https://docs.redpanda.com/cloud-data-platform-full.txt)

---
title: NULLIF
latest-operator-version: v26.1.4
latest-console-tag: v3.7.3
latest-connect-version: 4.93.0
latest-redpanda-tag: v26.1.9
docname: sql/sql-functions/other-functions/nullif
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: sql/sql-functions/other-functions/nullif.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-functions/other-functions/nullif.adoc
description: The `NULLIF` function replaces a given value with NULL if it matches a specific criterion.
page-topic-type: reference
page-git-created-date: "2026-05-26"
page-git-modified-date: "2026-05-26"
---

<!-- Source: https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-functions/other-functions/nullif.md -->

The `NULLIF` function replaces a given value with NULL if it matches a specific criterion.

## [](#syntax)Syntax

```sql
NULLIF(argument_1,argument_2);
```

The `NULLIF` function takes two arguments:

-   The first argument is the value to evaluate.

-   The second argument is the value to treat as NULL if the first argument matches it.


> 💡 **TIP**
>
> If the first argument matches the second argument, the `NULLIF` function returns `NULL`. Otherwise, it returns the first argument as-is.

## [](#examples)Examples

### [](#handle-equal-values)Handle equal values

In this case, the `NULLIF` function compares the values 4 and 4.

```sql
SELECT NULLIF (4, 4);
```

The result is `NULL` because the two values being compared are equal (4 = 4).

```sql
 if
----
```

### [](#handle-different-values)Handle different values

This example uses the `NULLIF` function to manage different values.

```sql
SELECT NULLIF (9, 0);
```

The result is `9` because the second value in the `NULLIF` function is 0 (the two values are not equal).

```sql
 if

  9
```

### [](#string-comparison)String comparison

In this case, the `NULLIF` function compares the strings `L` and `O`.

```sql
SELECT NULLIF ('L', 'O');
```

The result is `L` because the two strings being compared (`L` and `O`) are not equal. Therefore, the function returns the first string.

```sql
 if

 L
```

### [](#handle-default-values)Handle default values

Suppose there is an `employees` table with columns for `name` and `salary`. This query retrieves employee names and their adjusted salaries, where a salary of 0 is replaced with NULL:

```sql
CREATE TABLE employees (
    name TEXT,
    salary INT
);

INSERT INTO employees (name, salary)
VALUES
    ('John', 50000),
    ('Jane', 0),
    ('Roy', 0),
    ('Neil', 0),
    ('Michael', 75000);
```

View the records:

```sql
SELECT * FROM employees;
```

```sql
  name   | salary
---------+--------
 John    |  50000
 Jane    |      0
 Roy     |      0
 Neil    |      0
 Michael |  75000
```

This query retrieves employee names and their adjusted salaries, where a salary of 0 is replaced with NULL:

```sql
SELECT name, NULLIF(salary, 0) AS adjusted_salary
FROM employees;
```

The `NULLIF` function checks whether the `salary` value is 0. If it is, the function returns NULL. Otherwise, it returns the original `salary` value.

```sql
  name   | adjusted_salary
---------+-----------------
 John    |           50000
 Jane    |
 Roy     |
 Neil    |
 Michael |           75000
```

### [](#avoid-division-by-zero)Avoid division by zero

Suppose there is a `fractions` table with columns, a `numerator` and a `denominator`.

```sql
CREATE TABLE fractions (
    numerator INT,
    denominator INT
);

INSERT INTO fractions (numerator, denominator)
VALUES
    (10, 2),
    (20, 0),
    (15, 3),
    (75, 0),
    (15, 3);
```

View the table:

```sql
SELECT * FROM fractions;
```

```sql
 numerator | denominator
-----------+-------------
        10 |           2
        20 |           0
        15 |           3
        75 |           0
        15 |           3
```

Here, the `NULLIF` function is applied to the `denominator` column. If the `denominator` is 0, the function returns NULL, avoiding division by zero.

```sql
SELECT numerator, denominator, numerator / NULLIF(denominator, 0) AS "result" FROM fractions;
```

The result is shown in the result column.

```sql
 numerator | denominator | result
-----------+-------------+--------
        10 |           2 |      5
        20 |           0 |
        15 |           3 |      5
        75 |           0 |
        15 |           3 |      5
```