IFNULL
IFNULL(expression, replace_with_expression)
Section titled “IFNULL(expression, replace_with_expression)”- expression: This is the first parameter of `IFNULL` function. It’s an expression that will be evaluated and returned if its value is NOT NULL.
- replace_with_expression: This is the second parameter of the `IFNULL` function. If the initial expression evaluates to NULL, then this is the value or expression that will be returned instead.
Example
Section titled “Example”SELECT IFNULL(NULL, 'This is not null');Output
Section titled “Output”'This is not null'Explanation
Section titled “Explanation”The IFNULL function replaces NULL values with the specified replacement value. In this case, NULL is replaced with the string 'This is not null'.
IFNULL(expression_1, expression_2);
Section titled “IFNULL(expression_1, expression_2);”- expression_1: This is the expression that is evaluated first by the IFNULL function. If the value of expression_1 is not NULL, the function will return this value.
- expression_2: This is the alternative expression that the IFNULL function will return if expression_1 is NULL.
Example
Section titled “Example”SELECT IFNULL(name, 'No Name')FROM employees WHERE id = 7;Output
Section titled “Output”No NameExplanation
Section titled “Explanation”The IFNULL function in SQLite checks the first expression if it is NULL. If it is NULL, the function returns the second expression. In this example, the IFNULL function checks if the ‘name’ field of the employee with the ‘id’ of 7 is NULL. If it is NULL, it returns ‘No Name’.