NULLIF()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Returns NULL
or the first argument based on an equality comparison of the two arguments.
USAGE
NULLIF(value1, value2)
Argument Name | Description |
---|---|
| The two values to compare |
DETAILS
NULLIF()
is a control flow function that returns a result based on the equality of the two arguments:
The return value is
NULL
if the two arguments are equalThe return value is the first argument if the two arguments are not equal
EXAMPLES
With Literal Values
In the following examples, NULLIF()
is called with literal values:
SELECT NULLIF(1.0, 1.00) AS result;
+--------+
| result |
+--------+
| NULL |
+--------+
SELECT NULLIF(42, 8) AS result;
+--------+
| result |
+--------+
| 42 |
+--------+
Example Schema and Data
Some of the examples are based on the example table contacts
:
CREATE TABLE contacts (
first_name VARCHAR(25),
last_name VARCHAR(25),
email VARCHAR(25),
new_contact boolean
);
INSERT INTO contacts VALUES
('John', 'Smith', 'John.Smith@example.com', true),
('Jane', 'Smith', '', true),
('Joe', 'Smith', 'Joe.Smith@example.com', NULL);
Per-row Values
SELECT first_name, NULLIF(email, '')
FROM contacts;
+------------+------------------------+
| first_name | NULLIF(email, '') |
+------------+------------------------+
| John | John.Smith@example.com |
| Jane | NULL |
| Joe | Joe.Smith@example.com |
+------------+------------------------+