Explain CASE Expression in MySQL with syntax.
CASE statement is a conditional expression. It is used to execute specific statements when some search condition evaluates to TRUE.
Syntax 1:CASE WHEN condition THEN result
WHEN condition THEN result
WHEN condition THEN result
...
ELSE result
END
Syntax 2:When no value is matched, the statements are executed.
CASE value WHEN target_value THEN result
WHEN target_value THEN result
WHEN target_value THEN result
...
ELSE result
END
Example:CASE sample
WHEN NULL THEN SELECT 'This is test';
ELSE SELECT 'Not test';
END CASE;