---
title: iff function
description: Learn the syntax of the iff function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/iff
---

# `iff` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Returns `expr1` if `cond` is `true`, or `expr2` otherwise. This function is a synonym for [`if` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/if.md).

## Syntax

```
iff(cond, expr1, expr2)
```

## Arguments

* `cond`: A BOOLEAN expression.
* `expr1`: An expression of any type.
* `expr2`: An expression that shares a [least common type](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-datatype-rules.md#least-common-type-resolution) with `expr1`.

## Returns

The result is the common maximum type of `expr1` and `expr2`.

## Examples

```sql
> SELECT iff(1 < 2, 'a', 'b');
 a
```

## Related functions

* [`case` expression](https://docs.databricks.com/aws/en/sql/language-manual/functions/case.md)
* [`decode` (key) function](https://docs.databricks.com/aws/en/sql/language-manual/functions/decode.md)
* [`if` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/if.md)
