> 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/return.md).

# RETURN

## Syntax

```bnf
RETURN expr
```

The `RETURN` statement terminates execution of a [stored function](/docs/server/server-usage/stored-routines/stored-functions.md) and returns the value *`expr`* to the function caller. There must be at least one `RETURN` statement in a stored function. If the function has multiple exit points, all exit points must have a `RETURN`.

This statement is not used in [stored procedures](/docs/server/server-usage/stored-routines/stored-procedures.md), [triggers](/docs/server/server-usage/triggers-events/triggers.md), or [events](/docs/server/server-usage/triggers-events/event-scheduler/events.md). [LEAVE](/docs/server/reference/sql-statements/programmatic-compound-statements/leave.md) can be used instead.

The following example shows that `RETURN` can return the result of a [scalar subquery](/docs/server/reference/sql-statements/data-manipulation/selecting-data/subqueries/subqueries-scalar-subqueries.md):

```sql
CREATE FUNCTION users_count() RETURNS BOOL
   READS SQL DATA
BEGIN
   RETURN (SELECT COUNT(DISTINCT User) FROM mysql.user);
END;
```

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