beautypg.com

Saving queries – Pitney Bowes MapInfo Professional User Manual

Page 243

background image

18. Click OK to create the following table.

The first column contains the country name. The second column contains the population density.
Note that the countries are listed in alphabetical order (Order By: Country) and the population density
for each country listed is over 500 people per square mile (pop_1994/ Area(obj, "sq mi") > 500).

Example 2 - Computing Population Density with SQL

To set up an SQL Select statement that selects only those states with a high population density, do the
following:

1. On the File menu, click Open Table and open the STATES table in a Map window.

2. On the Query menu, click SQL Select and fill in the SQL Select dialog box.

Select Columns: *

from Tables: States

where Condition: (Pop_1990 / Total_Area) > 500

into Table Named: HIDENSITY

This creates a new table, HIDENSTY, that contains only those states with a relatively high population
density (population divided by total area). The asterisk (*) in the Select Columns box transfers all of
the columns in the STATES table to the HIDENSTY table.

3. On the File menu, click Save Copy As and save the Selection table. The table can be saved with

any filename.

The Help System contains these related topics:

Examples of Group by Columns

Example - Using the Group by Columns Field to Subtotal the Results Table

Example - Using the Order by Columns Field to Sort the Results Table

Saving Queries

Any query created using the Select or SQL Select commands can be saved as a MapInfo Professional
query table. Query tables consist of a .tab file and a .QRY file. After you have executed a Select or SQL
Select statement, on the File menu, click Save Query to save the query as a table. When you open this
table, the tables on which the query is based are re-opened and the query is re-executed.

Queries made against other queries cannot be saved as a table or in a workspace.

Note:

Saving Queries to Workspaces

You can also save queries in workspaces. When you open a workspace that contains a query, the query
will execute and any windows created by the query will redisplay. Unlike saving a query as a table, a
separate .tab file is not created when you save a query to a workspace.

To save queries to a workspace, the Save Queries in Workspaces check box must be selected
in the Startup preferences. MapInfo Professional selects this check box by default.

Note:

Activating Save Query when Using a Workspace

To activate the Save Query option when using a workspace, you must activate the Save Queries in
Workspaces option
in the Startup Preferences dialog box.

1. Choose Options > Preferences > Startup. The Startup Preferences dialog box displays.

2. Check the Save Queries in Workspaces option (default setting).

3. Click OK.

If you selected this option and open a workspace, the associated queries are regenerated. A separate
MapInfo Professional table (.tab) file for the queries is not created.

Only queries created using the SQL Select or Select commands are saved in a workspace.

Note:

243

MapInfo Professional User Guide

Chapter 9: Selecting and Querying Data