Which function returns NULL if expr1 = expr2?
A. CASE
B. IF()
C. IFNULL()
D. NULLIF()
Answer: Option D
Solution (By Examveda Team)
This question asks about a function in MySQL that checks if two expressions are equal. If they are equal, it returns NULL. Let's break down the options:Option A: CASE
The CASE function is used for conditional expressions. It doesn't specifically return NULL if two expressions are equal.
Option B: IF()
The IF() function also works with conditional expressions. It returns one value if a condition is true and another value if the condition is false. It doesn't directly return NULL based on equality.
Option C: IFNULL()
IFNULL() is used to return a specified value if an expression is NULL. It doesn't check for equality.
Option D: NULLIF()
This is the correct answer! The NULLIF() function is specifically designed for comparing two expressions. If expr1 and expr2 are equal, NULLIF() returns NULL. Otherwise, it returns expr1.
Example:
```sql SELECT NULLIF(5, 5); -- Returns NULL SELECT NULLIF(5, 6); -- Returns 5 ```
So, the answer is Option D: NULLIF().
Join The Discussion