> Header-based references and cross-file references introduced in version 0.30.0.
This guide provides detailed documentation on using SQL Seal to query markdown tables within your notes. For a basic introduction, see the [Querying Markdown Tables](/query-markdown-tables.md) page.
This approach is simple but can be fragile if you add or remove tables from your document, as the indices will shift.
## Referencing Tables by Header
Instead of using numeric indices, you can reference tables by the header they appear under, making your queries more resilient to document changes.
### Basic Header Reference
If you have a header followed by a table:
```markdown
# Monthly Expenses
| Date | Category | Amount |
| ---- | -------- | ------ |
| 2025-01-01 | Grocery | 20.40 |
```
You can reference this table using:
```sqlseal
TABLE expenses = table(Monthly Expenses)
```
This finds the first table that appears after the "Monthly Expenses" header. The reference is case-insensitive, so `table(monthly expenses)` works too.
### Multiple Tables Under the Same Header
If multiple tables exist under the same header, you can specify which one to use with a second parameter:
```markdown
# Financial Data
## Revenue by Category
| Category | Amount |
| -------- | ------ |
| Product A| 5000 |
| Service B| 7000 |
## Expense Breakdown
| Category | Amount |
| -------- | ------ |
| Salaries | 6000 |
| Rent | 2000 |
```
You can reference these tables using either:
```sqlseal
-- By subheader
TABLE revenue = table(Revenue by Category)
TABLE expenses = table(Expense Breakdown)
-- Or by parent header and index
TABLE revenue = table(Financial Data, 0) -- First table under Financial Data
TABLE expenses = table(Financial Data, 1) -- Second table under Financial Data