The SQL Select dialog box is somewhat complex. However, filling in the dialog box is not as hard as it might seem at first, because most of the dialog box is optional. For example, if you do not want to create sub-totals, leave the Group By Columns field blank.
Select Columns
This field tells MapInfo Pro which columns to include in your results table. By default, this field contains an asterisk (*). The asterisk tells MapInfo Pro that you want the results table to include every column from your table. If you want your results table to contain only some of the columns from your table, replace the asterisk with a comma-separated list of the names of the columns you want to use. For example, when querying the World table, you might specify the following Select Columns list:
Select Columns: Country, Population, Indust_Grwth
From Tables
This field tells MapInfo Pro which table(s) to query. You must enter the name of at least one table in the From Tables field. If you want MapInfo Pro to query two or more tables, enter a comma-separated list of table names.
If you enter two or more table names in the From Tables field, you must also specify an expression in the Where Condition field to tell MapInfo Pro how to join the tables.
If you enter two table names, MapInfo Pro automatically calculates an appropriate Where Condition expression. However, if you use three or more table names, you must manually modify the Where Condition expression. When you are doing a multi-table join, all of the tables must be base tables. You cannot use results tables (e.g. Query5) in multi-table SQL Selects.
Where Condition
This field serves different purposes, depending on the nature of your query. When you are querying a single table, the Where Condition field is optional. If your query involves joining two or more tables, you must specify a Where Condition expression, and that expression must identify how MapInfo Pro should join the two tables.
If you wish, you can enter filter criteria through the Where Condition field. To enter a filter criterion, type a logical expression that evaluates to either TRUE or FALSE. For example, when querying the World table, if you want to select only the rows having a Population value greater than five million, specify the following Where Condition clause:
Where Condition: Population > 5000000
You can enter in the Where Condition field up to 4096 bytes in Unicode.
Group By Columns
This field lets you subtotal your results table. If you enter a column name (or a comma-separated lists of column names) in the Group By Columns field, MapInfo Pro subtotals your query results and shows you only the subtotals, rather than showing you every row from your table.
Calculating subtotals is a two-step process:
- Enter a column name (or names) in the Group By Columns field.
- Enter the same column name(s) and aggregate operators (such as Sum or Count) in the Select Columns field.
The Group By Columns field is optional. If you leave the field blank (which is the default), MapInfo Pro will not calculate subtotals.
Order By Columns
This field lets you sort your results table. If you enter a column name (or a comma-separated list of column names) in the Order By Columns field, MapInfo Pro sorts the rows of your results table. By default, the rows are sorted in ascending order, A appears above B, and smaller numbers appear above larger numbers. To sort in descending order, follow the column name with the word Desc.
For example:
Order By Columns: Population desc
Into Table Named
This field lets you specify the name of the results table. By default, the results table is named Selection. If you want to assign the results table a different name, type that name in the Into Table Named field. The table name that you enter should not be the name of an open table.
If you use SQL Select frequently, and if you use Selection as your results table name, you may eventually end up with a large number of left-over results tables (e.g. Query1, Query2, Query3...). These Queryn tables do not do any harm; however, some people simply prefer not to have a large number of open tables. If you want to avoid having a lot of open Queryn tables, enter an alternate table name in the Into Table Named field. For example, if you enter the table name QResults:
Into Table Named: QResults
then each subsequent SQL Select operation will use QResults as the results table name. That way, you only have to deal with one results table (QResults), regardless of how many queries you perform.
Browse Results
If the Browse Results check box is checked, MapInfo Pro displays the query results in a Browser window.
Find Results In Current Map Window
Select this check box to find your query results in the current Map window.
Add Results To Current Map Window
Select this check box to add your query results to the current Map window.
Using the Drop-down Lists (Aggregates, Functions, Operators, etc.)
The right side of the SQL Select dialog box contains five drop-down lists: Tables, Columns, Operators, Aggregates, and Functions.
Drop-down lists let you fill in the SQL Select dialog box by pointing and clicking, as opposed to typing. In other words, these five drop-down lists are simply a shortcut to reduce the amount of typing you have to do.
For example, you must enter a table name in the From Tables field. You can do this by pointing and clicking:
- Click in the From Tables field, so that the insertion point is in the field.
- Click and hold-down the mouse button on the Tables drop-down list. A list of table names drops down.
- Drag the mouse down to the name of the table you want to query, and release the mouse button. MapInfo Pro copies the name of the chosen table into the From Tables field.
Save Template
Saves the dialog box settings as query templates.
Load Template
Loads the saved query templates.
See Also: