IF ELSE statement
The IF ELSE statement can be used as a main statement, or within a parent statement, to return a value depending on whether a condition, or a series of conditions match. The statement allows for multiple
ELSE IF expressions, and a final
ELSE expression, with no limit to the number of
ELSE IF conditional expressions.
IF @condition THEN @expression [ ELSE IF @condition THEN @expression ... ] [ ELSE @expression ] END
The following query shows example usage of this statement.
IF $scope = "admin" THEN ( SELECT * FROM account ) ELSE IF $scope = "user" THEN ( SELECT * FROM $auth.account ) ELSE  END
If-else statements can also be used as subqueries within other statements.
UPDATE person SET railcard = IF age <= 10 THEN 'junior' ELSE IF age <= 21 THEN 'student' ELSE IF age >= 65 THEN 'senior' ELSE NULL END ;