MySQL Control Flow Functions and Expressions

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 THEN branch if the condition in the WHEN branch is satisfied, otherwise, return the result in the ELSE branch.
  • 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 NULL if the first argument is equal to the second argument, otherwise, returns the first argument.