The IF statement executes one set of statements based on the result of evaluating condition expressions.
.-ELSEIF-----------------------. V | >>-IF----expression--THEN--statements-+--+------------------+---> '-ELSE -statements-' >--END IF------------------------------------------------------><
Each expression is evaluated in turn until one results in TRUE; the corresponding set of statements is then executed. If none of the expressions returns TRUE, and the optional ELSE clause is present, the ELSE clause's statements are executed.
UNKNOWN and FALSE are treated the same: the next condition expression is evaluated. ELSEIF is one word with no space between the ELSE and the IF. However, you can nest an IF statement within an ELSE clause: if you do, you can terminate both statements with END IF.
IF i = 0 THEN
SET size = 'small';
ELSEIF i = 1 THEN
SET size = 'medium';
ELSEIF j = 4 THEN
SET size = 'large';
ELSE
SET size = 'unknown';
END IF;
IF J> MAX THEN
SET J = MAX;
SET Limit = TRUE;
END IF;