# INTERVAL

## Syntax

```sql
INTERVAL(N0,N1,N2,N3,...)
```

## Description

Returns the index of the last argument that is less than or equal to the first argument, or is NULL.

Returns `0` if `N0 < N1`, `1` if `N1 <= N0 < N2`, `2` if `N2 <= N0 < N3` and so on or `-1` if `N0` is `NULL`. All arguments are treated as integers. It is required that `N1 <= N2 <= N3 <= ... <= Nn` for this function to work correctly because a fast binary search is used.

## Examples

```sql
SELECT INTERVAL(22, 24, 26, 28);
```

```
+--------------------------+
| INTERVAL(22, 24, 26, 28) |
+--------------------------+
|                        0 |
+--------------------------+
```

```sql
SELECT INTERVAL(22, 22, 22, 22, 23);
```

```
+------------------------------+
| INTERVAL(22, 22, 22, 22, 23) |
+------------------------------+
|                            3 |
+------------------------------+
```

```sql
SELECT INTERVAL(25, 24, 26, 28);
```

```
+--------------------------+
| interval(25, 24, 26, 28) |
+--------------------------+
|                        1 |
+--------------------------+
```

```sql
SELECT INTERVAL(27, 24, 26, 28);
```

```
+--------------------------+
| interval(27, 24, 26, 28) |
+--------------------------+
|                        2 |
+--------------------------+
```

```sql
SELECT INTERVAL(27, 25, 26, 27);
```

```
+--------------------------+
| interval(27, 25, 26, 27) |
+--------------------------+
|                        3 |
+--------------------------+
```

```sql
SELECT INTERVAL(23, 1, 15, 17, 30, 44, 200);
```

```
+--------------------------------------+
| INTERVAL(23, 1, 15, 17, 30, 44, 200) |
+--------------------------------------+
|                                    3 |
+--------------------------------------+
```

```sql
SELECT INTERVAL(10, 1, 10, 100, 1000);
```

```
+--------------------------------+
| INTERVAL(10, 1, 10, 100, 1000) |
+--------------------------------+
|                              2 |
+--------------------------------+
```

```sql
SELECT INTERVAL(22, 23, 30, 44, 200);
```

```
+-------------------------------+
| INTERVAL(22, 23, 30, 44, 200) |
+-------------------------------+
|                             0 |
+-------------------------------+
```

```sql
SELECT INTERVAL(10, 2, NULL);
```

```
+-----------------------+
| INTERVAL(10, 2, NULL) |
+-----------------------+
|                     2 |
+-----------------------+
```

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/server/reference/sql-structure/operators/comparison-operators/interval.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
