IF
On this page
If the first argument is true, returns second argument.
Syntax
IF (val, iftrue, iffalse)
Arguments
-
Any SQL objects
Return Type
The default return type depends on the type of arguments iftrue
and iffalse
.iftrue
or iffalse
result in an integer, the return type is an integer.
Examples
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 |
+-----------------+-------------------+--------------------+
Last modified: February 24, 2023