> 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

Execute code based on conditions. This control flow statement runs different blocks of SQL statements depending on whether a specified condition is true.

## 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](https://2988006611-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSsmexDFPv2xG2OTyO5yV%2Fuploads%2Fgit-blob-b92561f12a8cd5cfdd949ec741c8e49815feaf22%2Fif-statement-railroad.svg?alt=media)

## 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" %}
