> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> The loop table function in ClickHouse is used to return query results in an infinite loop.

# loop

<h2 id="syntax">
  Syntax
</h2>

```sql theme={null}
SELECT ... FROM loop(database, table);
SELECT ... FROM loop(database.table);
SELECT ... FROM loop(table);
SELECT ... FROM loop(other_table_function(...));
```

<h2 id="arguments">
  Arguments
</h2>

| Argument                    | Description                                                                                                          |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `database`                  | database name.                                                                                                       |
| `table`                     | table name.                                                                                                          |
| `other_table_function(...)` | other table function. Example: `SELECT * FROM loop(numbers(10));` `other_table_function(...)` here is `numbers(10)`. |

<h2 id="returned_values">
  Returned values
</h2>

Infinite loop to return query results.

<h2 id="examples">
  Examples
</h2>

Selecting data from ClickHouse:

```sql theme={null}
SELECT * FROM loop(test_database, test_table);
SELECT * FROM loop(test_database.test_table);
SELECT * FROM loop(test_table);
```

Or using other table functions:

```sql theme={null}
SELECT * FROM loop(numbers(3)) LIMIT 7;
   ┌─number─┐
1. │      0 │
2. │      1 │
3. │      2 │
   └────────┘
   ┌─number─┐
4. │      0 │
5. │      1 │
6. │      2 │
   └────────┘
   ┌─number─┐
7. │      0 │
   └────────┘
```

```sql theme={null}
SELECT * FROM loop(mysql('localhost:3306', 'test', 'test', 'user', 'password'));
...
```
