if

description

Syntax

if(boolean condition, type valueTrue, type valueFalseOrNull)

Returns valueTrue when condition is true, returns valueFalseOrNull otherwise.

The return type is the type of the result of the valueTrue/valueFalseOrNull expression

example

  1. mysql> select user_id, if(user_id = 1, "true", "false") test_if from test;
  2. +---------+---------+
  3. | user_id | test_if |
  4. +---------+---------+
  5. | 1 | true |
  6. | 2 | false |
  7. +---------+---------+

keywords

IF