Note that some SQL platforms use
IIF instead of
IF, as MySQL does.
IF statements, as shown below, it is necessary to use parentheses very deliberately.
IF([conditions], [value if conditions met], [value if conditions note met])
CASE returns a singular value based on conditional test(s). There are two syntaxes that can be used with
WHEN [condition set 1] THEN [result when condition 1 met]
WHEN [condition set 2] THEN [result when condition 2 met]
ELSE [result when no conditions met]
END AS alias
The simpler syntax when no values need to be manipulated:
CASE column_name or expression
WHEN [value 1] THEN [result when row=value 1]
WHEN [value 2] THEN [result when row=value 2]
ELSE [result when row does not equal specified values]
END AS alias
Order of Operations in Logical Expressions
The evaluation order of logical expressions in SQL is:
This statement evaluates as (2
This statement evaluates as (3
This statement evaluates as (1
Some content in this note are taken from the Jupyter Notebook below. They are accessible as part of the “Managing Big Data with MySQL” course on coursera.org, and licensed by Jana Schaich Borg under CC BY-NC 4.0.
- MySQL Exercise 10 Useful Logical Operators
Other content for this note is taken from the Coursera course “Managing Big Data with MySQL.”