Returns valueTrue when the condition is true, and returns valueFalseOrNull otherwise. The return type is determined by the result of the valueTrue/valueFalseOrNull expression.
IF(<condition>, <value_true>, <value_false_or_null>)
| Parameter | Description |
|---|---|
<condition> | The boolean condition to evaluate. |
<value_true> | The value to return if <condition> evaluates to true. |
<value_false_or_null> | The value to return if <condition> evaluates to false. |
The result of the IF expression:
valueTrue when the condition is true.valueFalseOrNull when the condition is false.SELECT user_id, IF(user_id = 1, 'true', 'false') AS test_if FROM test;
+---------+---------+ | user_id | test_if | +---------+---------+ | 1 | true | | 2 | false | +---------+---------+