-
Maz Ameli authored
* init * more detail about summarizing * start of notebook mode docs * describe how to do joins * Screenshot updates for Enterprise Sandboxing * Updated screenshots for segment & metric * Added section on new auto-run settings * Added a note about keyboard shortcuts to run part of a query * wrap up notebook mode docs * update old screenshots and remove some unused ones * update Number viz screenshot * update a bunch of viz screenshots [ci skip] * more viz screenshot updating [ci skip] * misc edits to user guide [ci skip] * update the severely outdated Getting Started guide [ci skip] * update more screenshots and the x-rays doc [ci skip] * update Alerts docs and screenshots [ci skip] * update new SQL doc [ci skip] * small edit to writing sql doc [ci skip] * remove unused GSG images [ci skip] * update crufty admin screenshots [ci skip] * remove package-lock.json added by mistake [ci skip] * resolve review feedback [ci skip] * address kdoh's comments and prettier some pages
Maz Ameli authored* init * more detail about summarizing * start of notebook mode docs * describe how to do joins * Screenshot updates for Enterprise Sandboxing * Updated screenshots for segment & metric * Added section on new auto-run settings * Added a note about keyboard shortcuts to run part of a query * wrap up notebook mode docs * update old screenshots and remove some unused ones * update Number viz screenshot * update a bunch of viz screenshots [ci skip] * more viz screenshot updating [ci skip] * misc edits to user guide [ci skip] * update the severely outdated Getting Started guide [ci skip] * update more screenshots and the x-rays doc [ci skip] * update Alerts docs and screenshots [ci skip] * update new SQL doc [ci skip] * small edit to writing sql doc [ci skip] * remove unused GSG images [ci skip] * update crufty admin screenshots [ci skip] * remove package-lock.json added by mistake [ci skip] * resolve review feedback [ci skip] * address kdoh's comments and prettier some pages
Asking more advanced questions in the SQL/native query editor
If you ever need to ask questions that can't be expressed using the question builder, you can use SQL instead.
What's SQL?
SQL (pronounced "sequel") stands for Structured Query Language, and is a widely used standard for getting data from databases. We won't try to teach you all about SQL in this guide, but to learn more about it, check out this SQL Tutorial.
Even if you don't understand SQL or how to use it, it's worthwhile to understand how works inside Metabase because sometimes other people will share SQL-based questions that might be useful to you.
Starting a new SQL query
If you have the permissions to use the SQL editor, when you click the Ask a Question button you'll see an option to start a new SQL query. There's also a shortcut to the editor in the top nav bar; it's the little console icon.
You can write SQL (or your database's native querying language) directly into the editor that appears.
To try it out, type the command select sum(subtotal), created_at from orders group by created_at
. Don't worry if you don't understand this just yet. Click the blue run button and note the table that comes back is the same as if you had asked for the sum of Subtotal in the Orders table, grouped by Created At.
Tip! You can run your SQL query by pressing ctrl
+ enter
on Windows, or command
+ return
on a Mac. You can also run only a specific section of a query by selecting the part you'd like to run and pressing ctrl
+ alt
+ enter
on Windows, or command
+ option
+ return
on a Mac.
Questions asked using SQL can be saved, downloaded, or added to a dashboard just like questions asked using the question builder.
Using SQL filters
If you or someone else wrote a SQL query that includes variables, your question might have filter widgets at the top of the screen. These let you modify and filter the SQL query before it's run, changing the results you might get.
Writing SQL queries that use variables or parameters can be very powerful, but it's also a bit more advanced, so that topic has its own page if you'd like to learn more.
Next: Creating charts
Now that you have an answer to your question, you can now learn more about visualizing answers.