Returns “YES” if the condition is true; otherwise, returns “NO”.
SELECT IF(500<1000, “YES”, “NO”); |
The IF() function outputs a value if a condition is true, or an alternative value if the condition is false.
IF(condition, value_if_true, value_if_false) |
Parameter |
Description |
condition |
Required: The value that will be evaluated |
value_if_true |
Required: The value that will be returned if the condition is true |
value_if_false |
Required: The value that will be returned if the condition is false |
Works in: |
From MySQL version 4.0 |
Returns 5 if the condition is true, otherwise returns 10.
SELECT IF(500<1000, 5, 10); |
Check if two strings are identical and return “YES” if they are, otherwise return “NO”.
SELECT IF(STRCMP(“hello”,“bye”) = 0, “YES”, “NO”); |
Returns “MORE” if the condition is true; otherwise, returns “LESS”.
SELECT OrderID, Quantity, IF(Quantity>10, “MORE”, “LESS”) FROM OrderDetails; |