Queries in Manifold are written in a language called SQL, the same SQL language that has become overwhelmingly popular through many years of use with databases.
An item in the project pane marked with a query icon is a component that contains SQL text in it. If we double-click a query, it opens up in a Command Window, which is a special console in Manifold that makes writing SQL queries easier.
New queries created within the Command Window disappear when the Command Window is closed. To save the query, choose Edit - Save As Query to save the query text as a query in the project.
In the main menu choose File - Create - New Query or right-click an empty spot in the Project pane and choose Create - New Query.
Name |
Name for the query. "Query" by default. Specify a more informative name as desired. |
Create Query |
Create the new query. |
Edit Query |
We can write SQL in a query that creates other components. For example, we can write a query that creates a table and a drawing. We can also write a query that creates a new query component.
The Edit Query button launch the Command Window loaded with a query that creates a new query using the given name. This is a a great way to learn how to use SQL to create queries. |
Cancel |
Exit the dialog without doing anything. |
Two ways to create and run queries - In Manifold, we have two ways to write and to use SQL:
Choose File - Create - New Query, to create a new, blank query and then double-click that new query to open it in a Command Window. Creating a new query component in the Project ensures that whatever we write into that query will be saved as part of the Project. Any edits we make in the Command Window will be automatically saved into that query.
Choose View - New Command Window - SQL to launch an SQL Command Window. Launching a Command Window allows us to write short snippets of SQL to do simple things quickly in situations where we do not want to create a query component in the project for later use. For example, we might want to try out a few commands in SQL, or launch a short SELECT command to see what we have in our data. If we end up writing something more elaborate that we decide we want to keep, we can save it as a query using Edit - Save as Query.
Editing Queries, Scripts and Comments
Command Window - Query Builder
Example: Create a Drawing from a Query - Everybody knows we can create a drawing from a table, but we can also create a drawing from a query. When the query reports different results the drawing changes too. This example show step by step how to create a query and then how to create a drawing from that query. We show how to command Manifold to write a query for us that grabs a selection, and then how to create a drawing based on that new query. This example duplicates the Drawings from Queries video using the Mexico_queries.mxb sample project that may be downloaded from the Examples page on the Manifold web site.
Example: Create and Run a Query - See how the different parts of a command window operate when creating and running SQL queries. Includes use of the Log tab as well as the ?expression and !fullfetch commands.
Example: Export the Results of a Query - How to export the results table of a query for use in other applications.
Example: Automatically Generating CREATE Queries - How to use the Command window to automatically generate SQL in the form of CREATE queries that create a desired component.
SQL Example: Learn SQL from Edit Query - Merging Areas - We learn how to write an SQL query that does a Merge : area (dissolve) operation by cutting and pasting from what the Edit Query button automatically generates.
Example: Transform Templates, Expressions and Queries - We learn to use a function by clicking on a template in the Transform pane, seeing what it does in a preview, looking at the query Manifold creates and then trying out the function in the Expression tab.