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

# SQL editor

> Write and execute SQL queries in Basedash

While Basedash excels at creating charts through natural language, you can also write custom SQL queries when you need more control or complex analysis.

## The SQL editor

### Features

* Syntax highlighting
* Auto-completion
* Schema browser
* Query history
* Result previews
* Performance metrics

## Writing queries

### Basic query structure

```sql theme={"dark"}
SELECT column1, column2
FROM your_table
WHERE condition
GROUP BY column1
ORDER BY column2 DESC
LIMIT 100
```

### AI query assistant

Need help writing SQL? Our AI can:

* Generate queries from natural language
* Explain complex queries
* Suggest optimizations
* Fix syntax errors

Just describe what you want to query, and the AI will help write the SQL.

## Query best practices

### Performance

* Use appropriate LIMIT clauses
* Avoid SELECT \*
* Index important columns
* Use efficient joins

### Organization

* Format queries for readability
* Add comments for complex logic
* Use CTEs for better structure

## Working with results

### Visualization

* Convert results to charts
* Export to CSV/Excel
* Share query results
* Save as dashboard components

### Result freshness

Results refresh when you rerun a query or change inputs. Basedash may temporarily cache some results in your browser to improve performance.

## Advanced features

### Variables

Use variables in your queries:

```sql theme={"dark"}
SELECT *
FROM orders
WHERE date >= {{start_date}}
  AND date <= {{end_date}}
```

## Security

* Read-only access by default
* Query history logging
* Resource usage limits
* Data access controls
