Mega Code Archive

 
Categories / MySQL Tutorial / Control Flow Functions
 

IF(expr1,expr2,expr3)

Syntax: IF(condition,true_value,false_value) If expr1 is TRUE (expr1 0 and expr1 NULL) then IF() returns expr2; otherwise it returns expr3. expr1 is evaluated as an integer value. mysql> mysql> SELECT IF(1>2,2,3); +-------------+ | IF(1>2,2,3) | +-------------+ |           3 | +-------------+ 1 row in set (0.00 sec) mysql> mysql> SELECT IF(1<2,'yes','no'); +--------------------+ | IF(1<2,'yes','no') | +--------------------+ | yes                | +--------------------+ 1 row in set (0.00 sec) mysql>