: less flexible from of the case expression
select if(username = 'darxysaq', 'high', 'low') as awesomeness
select case
when username = 'darxysaq' then 'high'
else 'low'
end as awesomeness
Case allows more than one branch.
select case
when username = 'darxysaq' then 'high'
when username = 'john skeet' then 'medium'
else 'low'
end as awesomeness
:if statement is an entirely different beast.
IF condition1 THEN
{...statements to execute when condition1 is TRUE...}
[ ELSEIF condition2 THEN
{...statements to execute when condition1 is FALSE and condition2 is TRUE...} ]
[ ELSE
{...statements to execute when both condition1 and condition2 are FALSE...} ]
END IF;
CREATE FUNCTION GetAwesomeness (username varchar(50))
RETURNS varchar(20)
BEGIN
IF username = 'darxysaq' THEN
return 'high';
ELSEIF username = 'john skeet' THEN
return 'medium';
ELSE
return 'low';
END IF;
END; //