Return "YES" if the condition is TRUE, or "NO" if the condition is FALSE:
SELECT IF(500<1000, "YES", "NO");
Try it Yourself »
The IF() function returns a value if a condition is TRUE, or another value if a condition is FALSE.
IF(
condition,
value_if_true,
value_if_false)
Parameter | Description |
---|---|
condition | Required. The value to test |
value_if_true | Required. The value to return if condition is TRUE |
value_if_false | Required. The value to return if condition is FALSE |
Works in: | From MySQL 4.0 |
---|
Return 5 if the condition is TRUE, or 10 if the condition is FALSE:
SELECT IF(500<1000, 5, 10);
Try it Yourself »
Test whether two strings are the same and return "YES" if they are, or "NO" if not:
SELECT IF(STRCMP("hello","bye") = 0, "YES", "NO");
Try it Yourself »
Return "MORE" if the condition is TRUE, or "LESS" if the condition is FALSE:
SELECT OrderID, Quantity, IF(Quantity>10, "MORE", "LESS")
FROM OrderDetails;
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!