To make a query:
- In the Selection group on the TABLE/MAP/SPATIAL tab, click on the SQL list and then click on Simple Select. The Simple Select dialog box displays.
- Click on the Select Records From Table drop-down list and choose the table from which to select the records.
- Type your query expression in the that Satisfy box, or click the Assist button to display the Expression dialog box which helps you write an expression.
- Type a name in the Store Results in table box for the temporary table that stores the results of your query or choose selection (the default). If Selection is chosen, MapInfo Pro automatically names the table Query 1, Query 2 etc.
- To sort the query by the value in some column (optional) click the Sort results by column drop-down list and choose the column containing the value you want to sort with.
- Click OK. A Browser window of your query results displays if the Browse Results box is checked.
You can use Select to highlight objects in a map or a table that meet certain criteria and create a results table that you can browse or map like any other table.
- When you are working in a Browser window, the records meeting the criteria of the query are highlighted.
- When you are working in a map, the graphic objects of the chosen records are highlighted.
- When you are working with both a Map window and a Browser window, the objects and the records are highlighted.
In all cases, a working table is automatically created called Query 3. This table contains the results of the query. You can map this table like any other table. The table can also be saved as a separate table with Save Copy As.
Saving Queries
You can save and reuse queries using the Save Query command (on the TABLE tab, in the Content group, click Save, and Save Table or Save Query). This command is enabled when you create a query using the SQL Select or Select command. Save Query is available only for queries created using SQL Select or Select commands.
Queries are saved using a MapInfo Pro table type. These tables consist of two files; a .TAB and a .QRY. Once a query is saved in one of these tables, it may be re-executed by simply opening the table.
Use the Saving a Template option to save a query statement and use it with an updated version of the table on which it was created or use it with a table containing the same fields as the table on which the query statement was created.
To save a query:
- Create a query using the Select or SQL Select command. This enables the Save Query Command.
- On the TABLE tab, in the Content group, click Save and Save Table or Save Query to open the Save Query dialog box.
Complete the Save Query dialog box to save the query as a MapInfo Pro table file (.TAB).
When you next open this .TAB file, the tables on which the query is based are re-opened and the query is re-executed.
Loading Templates
The Save Template and Load Template options in the Select and SQL Select dialog boxes allow you to save a query and reload the query statement. When you save a query, a .QRY file is created. The .QRY file is saved in the directory specified in Options/Preferences/Directories.
To load a template:
- Click Load Template in the SQL Select or Select dialog box. The Load Dialog From Query File dialog box opens.
- Choose the .QRY you want to use. The dialog box controls are filled in with the values saved in the template.
- Click Open to load the template.