Queries against your data are the building blocks for an analysis of the data. We covered the basics of writing your own queries in the article on query basics. In this article we'll look at all the things you can do with an existing query including how to:
- Use other people's queries
- Copy and save to dataset or project
- Make a template from the query
- Download query results
- Save results to a dataset or project
- Work with third-party applications
Use other people's queries
As you work in projects with other people, you might find a query that you want to use and edit, but it's not your query so you don't have permissions to save changes to it. The easiest thing to do is to make a copy of the query by selecting the three dots to the right of the query name in the project workspace and selecting Save a copy:
You'll be prompted to name the query and write a description. For tracking lineage it's a good idea to include the name of the original query in the description. Other save options include where--the current project or the original dataset--and who can see the new query (hidden by the location selection in the image below:
Copy and save to dataset or project
Normally the choice would be to save the new query in the current project because then it would show up in the list of all the queries and would be limited to contributors on the project. However if the query would be useful to others who create projects from that dataset, it might make more sense to save it directly to the dataset. Saving it to the dataset enables anyone with access to the dataset to use it (unless you also set it to share with no one). It's also the easiest way to save the query to another project that is linked to the same dataset. One note: queries saved to datasets show up in the Connected datasets section of the Project directory in the left sidebar--not under Queries: Alternatively you could copy and paste the query into a new query window in the other project and save it directly there.
Make a template from the query
Another way you might want to modify a query is to make a template from it so you can change the input strings to various parts of it. For example we could turn the query we just saved as Animal breed query into a query template by selecting the New template link at the top right of the query panel:
A dialog window will pop up giving you basic instructions to how query templates work and linking you to the documentation for query templates:
Select Add a sample statement a sample of the DECLARE statement used in query templates, a sample comment, and a link to the documentation will be inserted in the top of your query window:
With just a couple of modifications to the SQL you can have a query where other users can input values for animal types without ever having to know SQL themselves. Here we moved the comment to the top line so it would show up as a prompt in the input area, and we indicated where in the original query the input value would go (in the WHERE clause):
You can preview the query to see what other users will see and to test the query yourself by selecting the Preview query template link in the upper right corner of the query panel. Then fill in a value and hit Run query:
For more detailed information on query templates see the article on using query templates.
Download the query results
Another way to use a query is to download the results from it in either a csv or an xlsx file. After running your query, click the Download link below the query window and select the option you want:
Save results to a dataset or project
Another option for working with your query results is to save them as a tabular file in your current project, in an existing dataset, or in a new dataset:
There are many reasons you might want to save the results of your query in a new tabular file. See the article on saving query data to a new file for more information.
Two other ways you can use the results of a query are to make them available for download from a URL, or to embed them on a Markdown page. Both options are found in the Download menu under Copy URL or embed code. The URL is a download link for a csv file of the results and the embed code option renders the results table in a Markdown page.
work with third-party apps
There are many applications you can use to analyze and display the results of your queries, and we make it easy to work with your favorites. You can find out about the applications we integrate with on our integrations page. If you don't have any integrations configured yet you can still make visualizations of your results with our built-in Chart Builder app:
For instructions on how to use Chart Builder see one of the following articles on it: an introduction to Chart Builder, using the Vega-Lite editor, and incorporating multiple columns of data in your Chart Builder charts.
If you already have an integration configured that you want to use or want to integrate a new application, the name of the first application in your list of integrations will show up as a menu to the right of the Download button:
You can find out what integrations we currently offer and how to use them on our Integrations page.