MySQL Quiz : What is the output of the following query?
What is the output of the following query?
mysql> SELECT IFNULL(NULLIF(5, 5), 10);
A) 5
B) NULL
C) 10
D) Error
Correct Answer:
C) 10
Explanation:
In this query:
NULLIF(5, 5) returns NULL because both values are equal.
IFNULL(NULL, 10) returns 10 because the first argument is NULL.
Hence, the output of the query is 10.
mysql> SELECT IFNULL(NULLIF(5, 5), 10);
+————————–+
| IFNULL(NULLIF(5, 5), 10) |
+————————–+
| 10 |
+————————–+
1 row in set (0.01 sec)
mysql> SELECT NULLIF(5,5)
-> ;
+————-+
| NULLIF(5,5) |
+————-+
| NULL |
+————-+
1 row in set (0.00 sec)
mysql> SELECT IFNULL(NULL,10);
+—————–+
| IFNULL(NULL,10) |
+—————–+
| 10 |
+—————–+
1 row in set (0.00 sec)
MySQL Tutorials
MySQL Tutorials on this website: