IF(expr1,expr2,expr3) : IF : Control Flow Functions MySQL TUTORIALS


MySQL TUTORIALS » Control Flow Functions » IF »

 

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>
mysql> SELECT IF(1>2,2,3);
+-------------+
| IF(1>2,2,3|
+-------------+
|           |
+-------------+
row in set (0.00 sec)

mysql>
mysql> SELECT IF(1<2,'yes','no');
+--------------------+
| IF(1<2,'yes','no') |
+--------------------+
| yes                |
+--------------------+
row in set (0.00 sec)

mysql>
mysql>



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

MySQL TUTORIALS

 Navioo Control Flow Functions
» IF