The control flow functions allow you to add if-then-else logic to SQL queries without using the procedural code. The following show the most commonly used MySQL control flows functions:
- CASE – return the corresponding result in
THENbranch if the condition in theWHENbranch is satisfied, otherwise, return the result in theELSEbranch. - IF – return a value based on a given condition.
- IFNULL– return the first argument if it is not
NULL, otherwise returns the second argument. - NULLIF– return
NULLif the first argument is equal to the second argument, otherwise, returns the first argument.