[MySQL] IF Syntax

IF(expr1,expr2,expr3)

If expr1 is TRUE (expr1 <> 0 and expr1 <> NULL) then IF() returns expr2; otherwise it returns expr3IF()returns a numeric or string value, depending on the context in which it is used.

mysql> SELECT IF(1>2,2,3);
        -> 3
mysql> SELECT IF(1<2,'yes','no');
        -> 'yes'
mysql> SELECT IF(STRCMP('test','test1'),'no','yes');
        -> 'no'

 

 

Read Online: http://dev.mysql.com/doc/refman/5.7/en/control-flow-functions.html

http://dev.mysql.com/doc/refman/5.7/en/if.html

posted @ 2014-09-03 04:33  Zhentiw  阅读(238)  评论(0)    收藏  举报