Skip to main content

Explore data with SQL Lab

SQL Lab is where you explore a connection: look at its tables, answer a question in SQL, and turn the query you end up with into a dataset that charts and dashboards can use.

Run a query

What the video shows: In SQL Lab a query is typed that groups the Orders table by category and works out each category's margin and units sold, sorted by margin. Run Query shows the five categories in the results below, Beauty first.
  1. Choose a database

    Open SQL Lab and pick a connection under Database. Its tables appear in the schema browser.

  2. Write the query

    Type in the editor. Table, column and function names are suggested as you type, and after a table name and a dot, its columns.

    SQL
    SELECT category,
           SUM(revenue) AS revenue,
           ROUND(SUM(profit) / SUM(revenue), 3) AS margin
    FROM Orders
    GROUP BY category
    ORDER BY revenue DESC
  3. Run it

    Choose Run Query or press Ctrl+Enter (⌘+Enter on a Mac). The query runs in the background, so a long one never freezes the page; choose Stop to cancel it.

The schema browser, the editor, and the results of the last run.

The schema browser

Search tables...
Filter the list by name.
The arrow beside a table
Show its columns with their types. Columns load the first time you open a table.
Selecting a table
Puts its name in the editor. Double-click, or choose Query beside it, for a ready-made SELECT * query.

If the list says No database connections yet, add one first: see Connect a database or Upload a file.

The toolbar

Save
Keep the query as a saved query (see below).
Dataset
Save the query as a dataset (see below).
Query tabs
Work on several queries at once; + opens a new tab. Open tabs are kept in your browser, so they're still there tomorrow.
Share
Copy a link that opens this query, on the same connection, in SQL Lab. Whoever opens it still needs access to that connection.
Export
Download the query as a .sql file.
Last run
When this tab's query last ran.

Format and explain

Under the editor, beside Run Query:

Format
Lay the statement out over lines with consistent indentation, so it's easy to read.
Explain
Show the plan the database would follow, without running the query. Use it to find out why a query is slow. Select part of the query to explain just that part.
Explain opens the Plan tab with the database's own plan.

If the database or DataViz has a warning about a query you ran, it appears at the right of this row.

Results, logs and history

Results appear under the editor, a page at a time. The tabs above them:

Results
The rows. Search within them and page through them. If your workspace limits page size, a note says so.
Execution Log
What happened: status, connection, schema, row count and the message from the database.
Query Stats
Duration, number of rows and number of columns.
Plan
The plan from Explain, when you've asked for one.
History
Your recent runs. Choose one to put it back in the editor.

Download results

Download (arrow)
Save the page of rows on screen as a CSV file.
Download all (cloud)
Save every row as CSV. The query is run again a page at a time and the pages are joined; very large results stop at a maximum and say so.
Expand
Give the results more of the screen.

Save a query

Choose Save, give the query a name, and choose Save again. Saved queries are listed under Saved Queries in the sidebar for everyone who can read them; see Saved queries and history.

Save a query as a dataset

A query you'll chart, alert on or ask Insight AI about belongs in a dataset. Saving it from SQL Lab keeps the exact SQL you tested.

  1. Choose Dataset

    With the query in the editor (run it first, so DataViz knows its columns), choose Dataset.

  2. Name and describe it

    Enter a Dataset Name and, under Description / Business Context, what a row is and anything people should know, such as "one row per product category, all orders since January 2025".

  3. Choose the query mode

    Direct Query reads the database whenever a chart loads. Import Query stores a snapshot that charts read instead, refreshed on a schedule. See Live or imported.

  4. Save, then chart it

    Choose Save. DataViz offers Create Chart, which opens the chart editor with the new dataset already chosen.

Import options

With Import Query chosen, you also set how the snapshot is refreshed:

Full Refresh
Run the query again and replace the whole snapshot.
Semi Refresh
Add only new or changed rows, found with an Incremental Key: a column that only grows, such as updated_at or an id. Optionally name Unique Key Column(s) to merge changed rows, and a Partition Column to split the stored data.
Refresh Schedule
Manual (on demand), Hourly, Daily or Weekly.
What the video shows: In SQL Lab a query is typed that totals revenue and margin for each product category, and Run Query lists the five categories. Dataset opens Save Dataset; the dataset is named Revenue and margin by category and saved. Create Chart, offered straight after, opens the chart editor on the new dataset, where the chart type is switched from Table to Bar, category goes on the X axis and revenue into the metrics, and the preview draws a bar for each category.

Limits and safety

Read-only by default

SQL Lab runs queries that read data. Statements that change data or tables are refused unless the connection allows them (Allow DDL and DML).

Time and row limits

Each query has a time limit and a maximum number of rows, set by your admins under Governance and guardrails. A query that runs past the time limit is stopped with a message saying so.