Computer >> Computer tutorials >  >> Programming >> MySQL

What is the resemblance of COALESCE() function with IF-THEN-ELSE statement?


As we know that COALESCE() function returns first non-NULL value from the list of values. The following IF-THEN-ELSE statement is equivalent to COALESCE() function.

IF value1 is not NULL THEN
output = value1;
ELSIF value2 is not NULL THEN
output = value2;
ELSIF value3 is not NULL THEN
output = value3;
.
.
.
ELSIF valueN is not NULL THEN
output = valueN;
ELSE
output = NULL;
END IF;