# Ask your data a question
Open the **SQL editor**, click a table name to insert it, write a `SELECT` and press **Run** (Cmd or Ctrl Enter). From code, `nx.sql("...")` returns the same rows. Large results are paged, and the editor shows what a query reads before it runs.
## What you will build [#what-you-will-build]
Three SQL queries on a real table: a look at the rows, a count, and a grouped summary that answers a business question. Plus how to read large results and what to do when a query is refused.
The examples use an `orders` table with `order_id`, `customer`, `amount` and `created_at` columns. Use your own table and column names.
## Before you start [#before-you-start]
- A table in Nexus. If you have none, follow [Turn a spreadsheet into a table](/docs/guides/spreadsheet-to-table) first.
- Access to read that table. Owners and admins can read everything; members need **Read its data** given in [Data access](/docs/data/data-access).
- For developers: the SDK installed and an API key. See the [Quickstart](/docs/get-started/quickstart).
Add a `LIMIT` while you explore to keep results fast and inside your plan's size.
## Steps [#steps]
### Open the SQL editor [#open-the-sql-editor]
Go to . The side panel lists your schemas and tables; **Find a table** searches. Click a name to insert it, or start from **Preview rows** or **Count rows**.
### Look at the rows [#look-at-the-rows]
```sql
SELECT * FROM orders LIMIT 100
```
Select **Run** or press Cmd Enter (Ctrl Enter on Windows). The rows appear below with the row count.
### Count them [#count-them]
```sql
SELECT COUNT(*) AS orders FROM orders
```
### Answer a question [#answer-a-question]
Which customers spent the most last month?
```sql
SELECT customer, SUM(amount) AS total
FROM orders
WHERE created_at >= DATE '2026-10-01' AND created_at < DATE '2026-11-01'
GROUP BY customer
ORDER BY total DESC
LIMIT 10
```
### Read the cost before you run [#read-the-cost-before-you-run]
Above the results, the editor shows how much data the query reads, and warns before running one your plan does not allow. Narrow it with a `WHERE` clause on a date or key.
### Connect [#connect]
```python
from klarety import Nexus
nx = Nexus.connect() # reads KLARETY_API_KEY
```
### Run a query [#run-a-query]
```python
result = nx.sql("SELECT * FROM orders LIMIT 100")
print(len(result), "rows, read", result.bytes_scanned, "bytes")
for row in result.rows[:5]:
print(row)
```
### Pass values safely [#pass-values-safely]
Use `:name` placeholders and `params`. Each value is filled in as a string literal, never as SQL, so cast it where a number or date is meant:
```python
top = nx.sql(
"""
SELECT customer, SUM(amount) AS total
FROM orders
WHERE created_at >= CAST(:start AS DATE) AND created_at < CAST(:end AS DATE)
GROUP BY customer
ORDER BY total DESC
LIMIT 10
""",
params={"start": "2026-10-01", "end": "2026-11-01"},
)
print(top.rows)
```
### Estimate before running [#estimate-before-running]
`estimate` tells you what a statement would read and whether your plan allows it, without running it.
```python
print(nx.estimate("SELECT * FROM orders"))
```
### Read a large result [#read-a-large-result]
`max_rows` is 1 to 10,000, and at most your plan's page of rows comes back at once. When more rows exist, `truncated` is true and `result_rows` reads every row:
```python
result = nx.sql("SELECT * FROM orders", max_rows=10000)
if result.truncated:
for row in nx.result_rows(result):
...
```
## Check that it worked [#check-that-it-worked]
- The count matches the number of rows you expect in the table.
- The grouped query returns at most ten rows, largest total first.
- From code, `result.rows` is a list of dictionaries keyed by column name.
## If something goes wrong [#if-something-goes-wrong]
Check its exact name and schema in the side panel. From code, list tables with `nx.tables.list()`, or run `klarety tables`.
The whole result passed your plan's size. Narrow the query or add a `LIMIT`. Your limits are in , or `nx.limits()` from code.
You may not have **Read its data** on that table, or the query reads more than your plan allows. From code this raises `RefusedError` or `OverBudgetError`. See [Errors](/docs/developers/errors).
From code, a whole number past 2^53 comes back as text so no JSON reader rounds it. Convert it with `int()`.
## Next steps [#next-steps]
- [SQL editor](/docs/data/sql-editor): everything the editor does.
- [SQL from code](/docs/developers/sql): parameters, paging and errors in depth.
- [Send a daily report](/docs/guides/daily-report): have an agent run a query like this every morning.