> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
> Use this file to discover all available pages before exploring further.

> Reference material for IF function

# IF

Evaluates a condition and returns different results based on whether the condition is true or false. The `IF` function is a simplified alternative to the `CASE` expression for handling conditional logic.

## Syntax

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
IF(<condition>, <then>, <else>)
```

## Parameters

| Parameter     | Description                                                                                             | Supported input types |
| :------------ | :------------------------------------------------------------------------------------------------------ | :-------------------- |
| `<condition>` | Condition that the function evaluates.                                                                  | `BOOLEAN`             |
| `<then>`      | Value returned when `<condition>` evaluates to `true`.                                                  | Any                   |
| `<else>`      | Value returned when `<condition>` evaluates to `false` or `NULL`. Must match the data type of `<then>`. | Any                   |

## Return type

The `IF` function returns the same data type as the `<then>` and `<else>` parameters.

## Example

The following example classifies each level in the `levels` table as `'Hard'` when its `maxpoints` score threshold is 100 or above, and `'Easy'` otherwise:

<div className="query-window">
  ```
  SELECT level, name, IF(maxpoints >= 100, 'Hard', 'Easy') AS difficulty
  FROM levels
  ORDER BY level;
  ```

  | level <span>int null</span> | name <span>text null</span> | difficulty <span>text</span> |
  | :-------------------------- | :-------------------------- | :--------------------------- |
  | 1                           | Thunderbolt Circuit         | Easy                         |
  | 2                           | Velocity Vale               | Easy                         |
  | 3                           | Raceway Ridge               | Easy                         |
  | 4                           | Nitro Narrows               | Hard                         |
  | 5                           | Thunder Road                | Hard                         |
  | 6                           | Burnout Boulevard           | Easy                         |
  | 7                           | Speed Street                | Easy                         |
  | 8                           | Racing Ravine               | Hard                         |
  | 9                           | Drift District              | Hard                         |
  | 10                          | Acceleration Alley          | Hard                         |

  <p><span>Rows: 10</span><span>Execution time: 6.00ms</span></p>
</div>
