Important
The SingleStore 9.1 release candidate (RC) is available now. It will be promoted to general availability (GA) soon and at that time it will be renamed to SingleStore 10.
In the interim, SingleStore 9.1 RC can be used to preview, evaluate, and provide feedback on the new and upcoming features in SingleStore 10, while SingleStore 9.0 is recommended for production workloads.
IF
On this page
The IF() function returns second argument if the first argument is true.
Syntax
IF(condition, value_if_true, value_if_false)
Arguments
-
Any SQL objects
Return Type
Returns a value based on a specified condition.
Examples
Create a table and insert values:
CREATE TABLE orders(comp_id INT(10), comp_name VARCHAR(50),order_number INT(10), order_total INT(10));INSERT INTO orders VALUES("64","Wolf-Conn","4722","9"),("924","Blick, Von and Lynch","9610","52"),("487","Sipes-Bauch","5180","14"),("835","Shields-Kiehn","7961","684"),("476","Bogisich, Brown and Hessel","4687","482"),("809","Cole-Durgan","9358","467"),("232","Towne LLC","3774","445");
Create a query using the IF function:
SELECT order_number,comp_id,order_total,IF(order_total > 100, 'Yes', 'No') AS amount_greater_than_100FROM orders;
+--------------+---------+-------------+-------------------------+
| order_number | comp_id | order_total | amount_greater_than_100 |
+--------------+---------+-------------+-------------------------+
| 4687 | 476 | 482 | Yes |
| 9358 | 809 | 467 | Yes |
| 5180 | 487 | 14 | No |
| 3774 | 232 | 445 | Yes |
| 7961 | 835 | 684 | Yes |
| 4722 | 64 | 9 | No |
| 9610 | 924 | 52 | No |
+--------------+---------+-------------+-------------------------+Last modified: