> ## Documentation Index
> Fetch the complete documentation index at: https://docs.noxus.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# SQL Queries with Tables

> Query and join your tables with SQL, and what the limits are

You can run SQL from the table's search bar, the [Query Table](/platform/tables/using/flows) node, [agents](/platform/tables/using/agents), [Genie](/platform/tables/using/genie), the [SDK](/sdk/resources/tables) and the [API](/api-reference/v1--tables/query-tables).

## Writing a query

Refer to tables and columns by their **identifiers**, not their display names. You can find a table's identifier in its **Settings** tab, and copy a column's from its **Column options** menu.

Every table in the workspace can be queried by its identifier, including [platform tables](/platform/tables/platform-tables), so you can join across them freely.

<CodeGroup>
  ```sql Filter and sort theme={null}
  SELECT email, signups
  FROM customers
  WHERE active
  ORDER BY signups DESC
  LIMIT 20;
  ```

  ```sql Join two tables theme={null}
  SELECT c.name, COUNT(o.id) AS orders
  FROM customers c
  JOIN orders o ON o.customers_id = c.id
  GROUP BY c.name
  ORDER BY orders DESC;
  ```

  ```sql Join a platform table theme={null}
  SELECT u.email, COUNT(r.id) AS runs
  FROM platform_runs r
  JOIN platform_users u ON u.id = r.user_id
  GROUP BY u.email;
  ```
</CodeGroup>

## What's allowed

Each query must be exactly one statement.

| Allowed | Not allowed |
| :- | :- |
| `SELECT`, including `WITH` (CTEs), `JOIN`, `UNION`, subqueries and aggregates | DDL such as `CREATE`, `ALTER` and `DROP` |
| `INSERT`, `UPDATE` and `DELETE`, only [where writes are enabled](#writing-data-with-sql) | `TRUNCATE` |

## Writing data with SQL

The table's search bar only reads data. `INSERT`, `UPDATE` and `DELETE` run only in these places:

* **Query Table node**: turn on **Allow an INSERT statement**, **Allow an UPDATE statement** or **Allow a DELETE statement** under **Advanced options**. All three are off by default. See [Tables in Flows](/platform/tables/using/flows).
* **Agents**: turn on **Allow edits** for the table. `UPDATE` and `DELETE` must include a `WHERE` clause. See [Tables in Agents](/platform/tables/using/agents).
* **Genie**: changes to data ask for your approval first. See [Tables with Genie](/platform/tables/using/genie).

## Limits

* **Timeout**: a query is cancelled after 10 seconds.
* **Row cap**: a query returns at most 10,000 rows. Extra rows are dropped without an error, so add `LIMIT` and `ORDER BY` to control which rows you get. The search bar's SQL mode pages through results and isn't affected.
* **Concurrency**: a workspace runs a few queries at once and queues the rest. If no capacity frees up in time, the query is not run and you get an error asking you to try again.
* **Rate limit**: in the app, 5 queries per second per user. Through the API, 10 per second per workspace by default.

Agents use their own row and timeout limits; see [Tables in Agents](/platform/tables/using/agents#settings).

<Accordion title="Common errors">
  | Error | How to fix it |
  | :- | :- |
  | `relation "<name>" does not exist` | Use the table's identifier, not its display name. Platform tables start with `platform_`. |
  | `column "<name>" does not exist` | Use the column's identifier, not its name. |
  | `Could not parse SQL: syntax error at or near "..."` | Fix the SQL syntax near the quoted text. |
  | `Exactly one statement is allowed.` | Remove the extra statements after the first `;`. |
  | `Only SELECT statements are allowed.` | This place only reads data. Use the Query Table node with a write toggle, an agent with **Allow edits**, or Genie. |
  | `This statement runs an UPDATE. Switch on "Allow an UPDATE statement" to let this node change data.` | Turn on the matching toggle under **Advanced options** in the Query Table node. |
  | `Only SELECT, INSERT, UPDATE or DELETE statements are allowed.` | DDL and `TRUNCATE` can't run. Change tables and columns in the app instead. |
  | `Schema '<name>' is not allowed.`, `Table '<name>' is not allowed.`, `Function '<name>' is not allowed.` | System catalogs and system functions can't be queried. |
  | `Query exceeded the time limit and was cancelled.` | Add a `WHERE` clause or `LIMIT`, or simplify the joins. |
  | `Too many table queries are running for this workspace. The statement was not executed; try again.` | Try again, or run fewer flows and agents against tables at the same time. |
  | `Timed out waiting for a free database connection for this workspace's tables. The statement was not executed.` | Try again shortly. |
</Accordion>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.