# IFNULL

## Syntax

```sql
IFNULL(expr1,expr2)
NVL(expr1,expr2)
```

## Description

If *`expr1`* is not `NULL`, `IFNULL()` returns *`expr1`*; otherwise it returns\_`expr2`\_. `IFNULL()` returns a numeric or string value, depending on the context in which it is used.

`NVL()` is an alias for `IFNULL()`.

## Examples

```sql
SELECT IFNULL(1,0); 
+-------------+
| IFNULL(1,0) |
+-------------+
|           1 |
+-------------+

SELECT IFNULL(NULL,10);
+-----------------+
| IFNULL(NULL,10) |
+-----------------+
|              10 |
+-----------------+

SELECT IFNULL(1/0,10);
+----------------+
| IFNULL(1/0,10) |
+----------------+
|        10.0000 |
+----------------+

SELECT IFNULL(1/0,'yes');
+-------------------+
| IFNULL(1/0,'yes') |
+-------------------+
| yes               |
+-------------------+
```

## See Also

* [NULL values](https://mariadb.com/docs/server/reference/data-types/null-values)
* [IS NULL operator](https://mariadb.com/docs/server/reference/sql-structure/operators/comparison-operators/is-null)
* [IS NOT NULL operator](https://mariadb.com/docs/server/reference/sql-structure/operators/comparison-operators/is-not-null)
* [COALESCE function](https://mariadb.com/docs/server/reference/sql-structure/operators/comparison-operators/coalesce)
* [NULLIF function](https://mariadb.com/docs/server/reference/sql-functions/control-flow-functions/nullif)
* [CONNECT data types](https://mariadb.com/docs/server/server-usage/storage-engines/connect/connect-data-types#null-handling)

<sub>*This page is licensed: GPLv2, originally from*</sub> [<sub>*fill\_help\_tables.sql*</sub>](https://github.com/MariaDB/server/blob/main/scripts/fill_help_tables.sql)

{% @marketo/form formId="4316" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/server/reference/sql-functions/control-flow-functions/ifnull.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
