# Query with SQL Explorer

SQL Explorer is the in-app workspace for writing and running ad-hoc SQL against Altertable. Use it when you want to inspect tables, test joins, debug a query, or turn an exploration into a saved analysis.

Queries use the same [DuckDB SQL dialect](/docs/lakehouse/sql-engine.md) as the rest of the lakehouse. You can reference Altertable catalogs and external catalogs in one statement.

Ask Agent is available in SQL Explorer when you want help drafting or refining a query without leaving the workspace. Review the generated SQL before running it, especially when it writes data.

## Example

Join product usage to account data from another catalog:

```sql
SELECT
  accounts.name,
  COUNT(*) AS sessions
FROM product_analytics.analytics.web_sessions sessions
JOIN crm.public.accounts accounts
  ON sessions.account_id = accounts.id
WHERE sessions.started_at >= now() - INTERVAL '7 days'
GROUP BY accounts.name
ORDER BY sessions DESC
LIMIT 20;
```

## When to use it

Use SQL Explorer for fast iteration and one-off checks. Use [SQL insights](/docs/query-data/visualizations/insights.md#2-sql-insights) when the query should become a saved visualization, and use the [HTTP API](/docs/query-data/http-api.md) when application code needs to run queries programmatically.

## Learn more

- **[SQL engine](/docs/lakehouse/sql-engine.md)**: DuckDB dialect and cross-catalog queries.
- **[Insights](/docs/query-data/visualizations/insights.md)**: save SQL as reusable analyses.
- **[HTTP API](/docs/query-data/http-api.md)**: run SQL from scripts and applications.