Outdated Version

You are viewing an older version of this section. View current production version.

IF

If the first argument is true, returns second argument. If the first argument is false or NULL, returns third argument.

IF (val, iftrue, iffalse)

Arguments

  • Any SQL objects

Return Type

If the val evaluates to true, returns iftrue. Otherwise iffalse.

Examples

memsql> select if(0, 'a', 'b'), if('1', 'a', 'b'), if(NULL, 'a', 'b');
+-----------------+-------------------+--------------------+
| if(0, 'a', 'b') | if('1', 'a', 'b') | if(NULL, 'a', 'b') |
+-----------------+-------------------+--------------------+
| b               | a                 | b                  |
+-----------------+-------------------+--------------------+