You are viewing an older version of this section. View current production version.
Join the SingleStore Community Today
Get expert advice, develop skills, and connect with others.


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


IF (val, iftrue, iffalse)


  • Any SQL objects

Return Type

The default return type depends on the type of arguments iftrue and iffalse. For example, if iftrue or iffalse result in an integer, the return type is an integer. If they are both strings, the return type is a string, and so on.


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                  |