Search⌘ K
AI Features

Introduction to Flow Control Functions

Learn to use MySQL flow control functions such as CASE, IF, IFNULL, and NULLIF to handle conditional logic in SQL queries. Understand how these functions streamline query writing by simplifying complex conditional distinctions without relying on lengthy UNION operations.

We'll cover the following...

In imperative programming languages beyond SQL, flow control is an important concept we are often unaware of. For example, while we commonly use if statements in Python, we do not consider them to implement flow control. Rather, we think of the if statement as deciding between two different cases based on a condition:

Python 3.8
def is_even(number: int) -> bool:
"""Returns `True` iff `number` is even."""
return number % 2 == 0
number = 1
if is_even(number):
print(f"{number} is even.")
else:
print(f"{number} is odd.")

In the example above, is_even checks whether a given number is even. Here, the if statement is not even the only construct of flow control. As a function, is_even also implements flow control as the control of flow ...