Write or edit a SQL query on a database
When you connect a SQL database, the connector workspace opens a SQL view: click a table, change the query that reads it, check the rows, and click Save as dataset. While saving you choose what each refresh does (see Choose how a database dataset refreshes). The SQL view works on PostgreSQL, MySQL, SQL Server, Oracle Database, Amazon Redshift, Snowflake, Google BigQuery, Databricks, Apache Hadoop and SAP HANA. MongoDB lists collections only, without a SQL view.
Before you start
Connect the database first: see Connect a database or app. If it sits behind a firewall, see Allow Mammoth through your firewall.
How the SQL view is laid out
After you connect a database, Tables on the left lists the tables the connection can read, grouped by schema or dataset where the database has them (use Filter tables to narrow it). The SQL query view on the right shows the open table's rows, with the query that read them above. Click Ask AI to open the connector's chat beside them.

Open a database table
In Tables, click a table. Mammoth puts a SELECT * FROM query for that table above the grid, runs it and shows the rows. To bring in only some columns, tick them in the table's header: the query changes to read only those columns, and you can save without running it again.
Edit or write the SQL query
-
Click the query line, or Edit SQL beside it, to open the editor.
-
Change the SQL to filter rows, pick columns or join tables, for example:
SELECT order_id, customer_id, amount, created_at FROM orders WHERE created_at >= '2024-01-01'Use the table and column names from your own database. Mammoth quotes names the way each database expects when it writes the query for you.
-
Click Run, or press Ctrl+Enter (⌘↵ on a Mac). Click Stop to cancel a long run.
-
Click Done to close the editor.
The status line shows how many rows came back and how long the query took, for example Ran in 1.2 s. If the query fails, the error appears under the editor. Click Fix with AI to send the query and the error to the chat.
Filter in the query: bringing in only the rows you need makes the dataset faster to refresh and lighter on your database. See Speed up pipelines and connectors.
Write SQL from a plain-language description
On PostgreSQL, MySQL, SQL Server and SAP HANA, the editor has a Describe the data you need... box.
- Type what you want, for example "sales by region last quarter".
- Click Write SQL. Mammoth writes the query from your tables.
- Review it and click Run.
If it can't, it says Couldn't write SQL for that. Try describing it differently. On the other databases, write the SQL yourself or ask the chat.
Troubleshooting queries and previews
| Symptom | Cause | Fix |
|---|---|---|
| No tables appear | The database user can't see any tables | Check its permissions in the database, then click Refresh list. If Mammoth can't list them at all, the list says Couldn't list the tables. |
| No rows came back. | The query ran but matched nothing | Check the WHERE clause |
| Still reading orders stays on screen | A large table takes a while to read | Click Stop and narrow the query with a WHERE clause |
| The query fails with an error | A SQL error | Read the error under the editor, or click Fix with AI |
| Couldn't write SQL for that. Try describing it differently. | Mammoth couldn't turn your description into SQL | Describe it differently, or write the SQL yourself |
Related
- Connect a database or app: the launcher, connection form and workspace.
- Allow Mammoth through your firewall: IP address and ports.
- Choose how a database dataset refreshes: refresh options and key columns.
- Speed up pipelines and connectors: incremental refresh and query filtering.
Something wrong? support@mammoth.io