> 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/geometry-constructors/geometry-relations/within.md).

# WITHIN

## Syntax

```bnf
Within(g1,g2)
```

## Description

Returns `1` or `0` to indicate whether `g1` is spatially within `g2`. This tests the opposite relationship as [Contains()](/docs/server/reference/sql-statements/geometry-constructors/geometry-relations/contains.md).

`WITHIN()` is based on the original MySQL implementation, and uses object bounding rectangles, while [ST\_WITHIN()](/docs/server/reference/sql-statements/geometry-constructors/geometry-relations/st-within.md) uses object shapes.

## Examples

```sql
SET @g1 = GEOMFROMTEXT('POINT(174 149)');
SET @g2 = GEOMFROMTEXT('POINT(176 151)');
SET @g3 = GEOMFROMTEXT('POLYGON((175 150, 20 40, 50 60, 125 100, 175 150))');

SELECT within(@g1,@g3);
+-----------------+
| within(@g1,@g3) |
+-----------------+
|               1 |
+-----------------+

SELECT within(@g2,@g3);
+-----------------+
| within(@g2,@g3) |
+-----------------+
|               0 |
+-----------------+
```

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