Making Queries using the SQL window - MapInfo_Pro - 2023

MapInfo Pro Help

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapInfo Pro
Version
2023
Language
English
Product name
MapInfo Pro
Title
MapInfo Pro Help
First publish date
1985
ft:lastEdition
2023-09-12
ft:lastPublication
2023-09-12T16:39:16.995549

Use the SQL window to build and execute SQL queries and statements. The SQL window is essentially a script editor wherein you can write and execute one or more SQL statements. The scripts are run using the immediate mode interpreted MapBasic and are not compiled.

For details about the SQL window, please see SQL Window.
Note: All limitations of the MapBasic window apply to the SQL window as well.

To create a query using the SQL window:

  1. Open the tables you wish to query on if you have not already done so.
  2. On the MAP tab, in the Selection group, click on the SQL list and then click on SQL to open the SQL window. When the SQL window opens for the first time, a select statement template is pre-loaded in the script pane.
  3. Write a SQL script in the script pane and click the Run button at the bottom of the SQL window to execute the script. Depending on your script and output selections, the results are displayed in a browser window, on a map, or saved to a file. The first time you write and run a script:
    • It is given a name based on the type of statement and tables used. It is marked as modified with an "*" before the name to indicate that it has been modified.
    • It shows up at the top of the Recent scripts list. If you edit a script and rerun, the script is updated with the changes, and a new script is added to the list with an incremental version number appended to the original file name (for example, .1" or ".2"). A history of changes is maintained this way.

The SQL List Drop-down (accessed by clicking on SQL, On the MAP tab > Selection group) also contains a list of the most recent SQL scripts created using the SQL window. When you hover over a script name in that list the following controls become visible:

Rename Script - To rename an SQL script, click the Rename Script button in the Recent list.

Save Script to disk - To save an SQL script, click the Save Script button in the Recent list. A script cannot be saved unless it has a valid name.
Note: When an unsaved script is saved, it is given its own group.
Edit Script - To edit an SQL script, click the Save Script button in the Recent list. A script cannot be saved unless it has a valid name.
Note: When an unsaved script is saved, it is given its own group.
Mark as Favorite - Click on the Mark as Favorite button to add your selected script to the Favorites list in the SQL drop-down list. Click again to toggle and Mark as Not Favorite.
Note: When an unsaved script is marked as favorite, it is saved and given its own group.