The function that returns a value based on a condition is MYSQL IF function. Hence MYSQL IF function is one of the control flow functions.
The syntax of the MySQL IF function is as follows:
IF(expr,if_true_expr,if_false_expr)
For example, If we have a table "address" with the column "userid, city, state, country" in which some state values are NULL. We want to print 'N/A' where the state value is null.
SELECT userid, city, IF(state IS NULL, 'N/A', state) state, country FROM address;
0 Comment(s)