Skip to main content
Version: V1.1.0

IF

Declaration

IF(expr1,expr2,expr3)

Description

If expr1 is TRUE (that is, expr1 is not equal to 0 and not equal to NULL), the result is expr2. Otherwise, the result is expr3.

The result of IF() can be either a numeric or string type, depending on the context.

If only one of expr2 or expr3 is explicitly NULL, the result type of IF() is the type of the non-NULL expression.

Examples

SELECT IF(5>6, 'T','F'), IF (5>6, 1, 0), IF(NULL, 'TRUE', 'FALSE'), IF(0, 'TRUE', 'FALSE')\G
*************************** 1. row ***************************
IF(5>6, 'T','F'): F
IF (5>6, 1, 0): 0
IF(NULL, 'TRUE', 'FALSE'): FALSE
IF(0, 'TRUE', 'FALSE'): FALSE
1 row in set (0.001 sec)