Important

Helios features are now enabled during weekly update windows and are no longer directly tied to SingleStore engine releases. Refer to the release notes to view the latest features available in your Helios cluster.

IF

The IF() function returns second argument if the first argument is true. The function returns third argument if the first argument is false or NULL.

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_100
FROM 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:

Was this article helpful?