IF(expr1,expr2,expr3)
If expr1 is TRUE (expr1 <> 0 and expr1 <> NULL) then IF() returns expr2; otherwise it returns expr3. IF() returns a numeric or string value, depending on the context in which it is used.
Note: There is also an IF statement which differs from the IF() function described here.
SELECT IF(1>2,2,3); +-------------+ | IF(1>2,2,3) | +-------------+ | 3 | +-------------+
SELECT IF(1<2,'yes','no'); +--------------------+ | IF(1<2,'yes','no') | +--------------------+ | yes | +--------------------+
SELECT IF(STRCMP('test','test1'),'no','yes');
+---------------------------------------+
| IF(STRCMP('test','test1'),'no','yes') |
+---------------------------------------+
| no |
+---------------------------------------+
There is also an IF statement, which differs from the IF() function described above.
© 2019 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/if-function/