MySQL If

 

IF function

The IF function is used to evaluate an expression and return a value.

The IF function consists of three parts.
1. condition to evaluate.
2. expression(can be another IF function) or value if the condition is evaluated to true.
3. expression(can be another IF function) or value if the condition is evaluated to false.

IF(condition, if_true_expr_or_value, if_false_expr_or_value)

Our example above shows ‘no sales rep’ if the condition(sales_rep_id IS NULL) is true and ‘sales rep’ if false.

IF function with aggregate functions

Here we are summing up the number of customers with and without reps.

 

 




Subscribe To Our Newsletter
You will receive our latest post and tutorial.
Thank you for subscribing!

required
required


Leave a Reply

Your email address will not be published. Required fields are marked *