> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/if.md).

# IF

## Syntax

```bnf
IF search_condition THEN statement_list
    [ELSEIF search_condition THEN statement_list] ...
    [ELSE statement_list]
END IF
```

![Railroad diagram of the IF statement — equivalent to the BNF above](/files/adjWT7CTJC89GCPz9mZO)

## Description

`IF` implements a basic conditional construct. If the `search_condition` evaluates to true, the corresponding SQL statement list is executed. If no `search_condition` matches, the statement list in the `ELSE` clause is executed. Each statement\_list consists of one or more statements.

## See Also

* The [IF() function](/docs/server/reference/sql-functions/control-flow-functions/if-function.md), which differs from the `IF` statement described above.
* [Changes in Oracle mode](/docs/release-notes/community-server/about/compatibility-and-differences/sql_modeoracle.md).
* The [CASE statement](/docs/server/reference/sql-statements/programmatic-compound-statements/case-statement.md).

<sub>*This page is licensed: GPLv2, originally from*</sub> [<sub>*fill\_help\_tables.sql*</sub>](https://github.com/MariaDB/server/blob/main/scripts/fill_help_tables.sql)

{% @marketo/form formId="4316" %}
