Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

IFNULL

Example

Return a specified value if the expression is NULL; otherwise, return the expression.

SELECT IFNULL(NULL, “W3Schools.com”);

Definition and Usage

The IFNULL() function returns a specified value if the expression is NULL.

If the expression is NOT NULL, it returns the expression itself.

Syntax

IFNULL(expressionalt_value)

Parameter Values

Parameter

Description

expression

Required. The expression to check for NULL.

alt_value

Required. The value to return if the expression is NULL.

Technical Details

Works in:

 From MySQL version 4.0

More Examples

Example

Return the specified value if the expression is NULL; otherwise, return the expression itself.

SELECT IFNULL(“Hello”“W3Schools.com”);

Example

Return the specified value if the expression is NULL; otherwise, return the expression.

SELECT IFNULL(NULL, 500);