Switchboard Docs
Analysis

Build an explore with SQL

Save a SQL query as a document tile

A SQL base is a saved query used as the input to an explore. The result can appear as a table, chart, or scorecard in a document. For a temporary query, use the SQL scratchpad.

Before you start

You need permission to edit the document and query every model or source table used by the query. Use the SQL dialect shown in the editor. See the SQL reference.

Create the tile

  1. Open a document and select Edit.
  2. Type / in an empty block and choose Explore.
  3. Select Write SQL in the source picker.
  4. In SQL base, use Data browser to find accessible models or source tables.
  5. Write the query. Give each output column a clear, unique name.
  6. Select Run (Cmd+Enter) to preview the result.
  7. Select Save to create the SQL base and return to the explore.
  8. Choose its fields and visualization.
  9. In Manual save, select Save changes on the document.

This query checks the editor without needing a business table:

SELECT 1 AS example_value

Use references such as {{models.orders}} for models and {{sources.source_name.table_name}} for source tables. Replace these invented names with entries from Data browser. The SQL defines joins, aggregations, and column names for this tile.

Select Format in the SQL editor to arrange the query for reading. Formatting does not execute the query. Use Run (Cmd+Enter) to check the result before saving.

Check the preview and saved result

Run (Cmd+Enter) previews the first 100 rows with a 30-second timeout. A preview is a sample. Check the saved tile before using its totals in a report.

SQL errors appear in the editor. Correct the reported expression or reference, then run the query again. If access is denied, check access to every referenced table. A successful query in another tool does not grant access here.

In the tile editor, open the source-name menu and select Edit SQL to change its query. If the existing query fails to load, select Retry before editing it.

Next step

Add document filters, checking that each filter maps to the intended SQL output field.

On this page