|
|
||
| SQL Select: The "Super-Select" Presented at the Puget Sound MapInfo User Group July 9, 2002 John Schlosser, Schlosser Geographic Systems, Inc. (SGSI). Edited July 2004 and again January 2008. |
|
|||
Overview
|
||||
What is "SQL"?
|
||||
| MapInfo's SQL Two ways to use SQL: In this case dialogs mask the complexity of SQL, but MapInfo is using SQL "behind the scenes" nonetheless. MapInfo's internal implementation of SQL is not as complete as Oracle's or IBM's implementation. There is still more SQL power in MapInfo Pro than 99% of people will use. MapInfo's SQL support is still more complete than any other GIS. Tip: Keep your MapBasic window open at all times, and see how SQL commands are built by MapInfo. 2. To compose & send SQL commands to remote databases such as DB2, Oracle and SQL Server. In this case, MapInfo can send the most complex queries supported by the remote DBMS. The syntax is interpreted by the remote DBMS, not by MapInfo. MapInfo receives the results of the SQL query and treats it as a MapInfo table. Summary: There is still more SQL power in MapInfo Pro than 99% of people will use. MapInfo's SQL Spatial syntax: MapInfo offers spatial extensions to SQL syntax: e.g., "...where Table1Pnt.obj WITHIN Table2Region.obj" |
||||
| SQL Select vs. simple Select: Examples When to use SQL Select instead of the simple Select? To view selected, not all columns: SELECT col1, col5, col3 FROM MyTable To sort your results by more than one column: SELECT col1, col5, col3 FROM MyTable ORDER BY col5, col1 To aggregate or summarize table values: SELECT CountyFIPS, Sum(Pop_Tract) FROM PopByTract GROUP BY CountyFIPS To temporarily join and display values from two tables: SELECT Table1.CountyFIPS, Table1.CountyRevenue, Table2.CntyFIPS, Table2.Population FROM Table1, Table2 WHERE Table1.CountyFIPS = Table2.CntyFIPS INTO qComboTbl1_Tbl2 To temporarily rename columns: SELECT Pop1990_2002 "Pop Change" FROM MyPopTable Tip: Since SQL Select does everything, why not ignore the simple Select menu entirely? |
||||
| SQL ExamplesFinding Points Outside a Region
The resulting table will be a list of points that fall outside a region object. 1. Open point and boundary file. 2. Select objects in the boundary file. 3. Perform the following SQL:
The resulting table will list the boundary name and the number of points that are contained inside the region. 1. Open Boundary and Points tables. 2. Perform the following SQL Select:
Using "ANY", "ALL" & "IN" syntax: = ANY compares separately against each value in a list of items. E.g.,SELECT * FROM tablename WHERE STATE_ABBR = ANY
("NY", "CA") SELECT * FROM tablename WHERE STATE_ABBR <> ANY
("NY", "CA") IN functions like = ANY . It lets you select any item from a set. ALL compares against the list as a whole. E.g.,
NOT IN is equivalent to the <> ALL term. [Notice the quotes.]
|
||||
| Tricks & Traps I used a "Group By" clause to summarize my table, now the table does not show on the map at all. Why? Description: I tried to specify a long list of column names and other long entries in the SQL Select dialog box. But only part of my entries were processed. Why? Description:
|
||||
| SGSI Product
support: > http://www.sgsisupport.com/ NW MapInfo User Group > http://www.miuser.com/ |
Terms of use |
Trademarks & copyrights | SGSI Home | Top of page |
Seattle,
WA: 206-224-0800 |
||