Skip to main content

IF

Introduced or updated: v1.2.738

If <cond1> is TRUE, it returns <expr1>. Otherwise if <cond2> is TRUE, it returns <expr2>, and so on.

Syntax

IF(<cond1>, <expr1>, [<cond2>, <expr2> ...], <expr_else>)

Aliases

Examples

SELECT IF(1 > 2, 3, 4 < 5, 6, 7);

┌───────────────────────────────┐
if((1 > 2), 3, (4 < 5), 6, 7)
├───────────────────────────────┤
6
└───────────────────────────────┘
Try Databend Cloud for FREE

Multimodal, object-storage-native warehouse for BI, vectors, search, and geo.

Snowflake-compatible SQL with automatic scaling.

Sign up and get $200 in credits.

Try it today