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

# Conditional Functions

> Conditional logic: IF, COALESCE, NULLIF, CASE

## Conditional functions

### COALESCE

Returns the first non-null value.

```sql theme={null}
SELECT COALESCE(preferred_email, backup_email, 'unknown') AS email
FROM company_data."123"
```

### NULLIF

Returns NULL if two values are equal.

```sql theme={null}
SELECT NULLIF(status, 'unknown') AS clean_status
FROM company_data."123"
```

### IF

Conditional expression (ternary).

```sql theme={null}
SELECT IF(score > 90, 'A', 'B') AS grade
FROM company_data."123"
```

### CASE

Multi-branch conditional expression.

```sql theme={null}
SELECT
  CASE
    WHEN score >= 90 THEN 'A'
    WHEN score >= 80 THEN 'B'
    WHEN score >= 70 THEN 'C'
    ELSE 'F'
  END AS grade
FROM company_data."123"
```

***

## Related content

<CardGroup cols={2}>
  <Card title="String Functions" icon="font" href="/nql/functions/string-functions">
    Text manipulation
  </Card>

  <Card title="Operators" icon="calculator" href="/nql/operators">
    Comparison and logical operators
  </Card>

  <Card title="All Functions" icon="function" href="/nql/functions/index">
    Browse all function categories
  </Card>

  <Card title="Data Types" icon="shapes" href="/nql/data-types">
    NULL handling and type coercion
  </Card>
</CardGroup>
