IF Function
Return one of two values based on a condition. This function evaluates a boolean expression and returns the first value if true, or the second if false.
Syntax
IF(expr1,expr2,expr3)Description
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 theIF() function described here.
Examples
SELECT IF(1>2,2,3);
+-------------+
| IF(1>2,2,3) |
+-------------+
| 3 |
+-------------+SELECT IF(1<2,'yes','no');
+--------------------+
| IF(1<2,'yes','no') |
+--------------------+
| yes |
+--------------------+See Also
There is also an IF statement, which differs from the IF() function described above.
This page is licensed: GPLv2, originally from fill_help_tables.sql
Last updated
Was this helpful?

