Advanced Tasks : Creating SQL queries to select features

Creating SQL queries to select features
On the layers where your administrator has enabled it, Query Builder gives you the option of selecting features on the map using an SQL query. You need not be an SQL expert to be able to use Query Builder though understanding the basics is necessary. Query Builder has both a graphical user interface and a SQL statement panel where you enter an SQL WHERE statement that applies to the layer you select.
By default Query Builder opens displaying its graphical user interface. You can create a query using the graphical tools and then switch to the SQL statement panel to view the SQL query. If, however, you edit the SQL WHERE statement, switching back to the graphical display will not translate the SQL statement graphically. If you start to edit on the SQL statement panel, you must execute the SQL statement you create from there.
Creating an SQL query graphically
1.
a.
Click the Map Content and Legend button at the top left of the interactive map and select a layer where you want to create a selection. On the right of the selected layer, click Layer Options , hover over Query Builder and then select Build Query.
b.
If the Map Tools pane is not expanded, in the map viewer, click the Map Tools button. Click the Map Tools button at the top right of the interactive map. On the Map Tools pane, click the More Tools button and then click the Query Builder icon . From Layer, select the feature group where you want to make a selection using a SQL statement. Depending on where your administrator has enabled Query Builder, not all layers may be available.
Figure 320 
2.
If a feature’s attribute data satisfy the condition you define, its attribute data is displayed in the Results window and the feature is displayed on the map.
Table 38 
For a feature to be returned in the results, its attribute data must satisfy one of the conditions in the WHERE statement you define.
For a feature to be returned in the results, its attribute data must satisfy all the conditions in the WHERE statement you define.
NOTE: 
Figure 321 
Grouping or ungrouping SQL conditions
You can build complex statements by creating several conditions and grouping them or ungrouping them as necessary.
Figure 322 
Once you have created any statements you want to group, select their check boxes and then the Group Selected button or Ungroup Selected button to group or ungroup them.
Figure 323 
In the example shown in Figure 323 , the first two statements have been grouped, and the next two statements have also been grouped.
In Group 1, all those parcels containing condominium buildings and where the number of units exceeds 25 are sought. The operator in this group is AND, meaning both conditions in this statement must be true.
The operator relating Group 1 to Group 2 is AND, meaning those parcels containing condominium buildings with more than 25 units must also be located in either Ward 5 or 6.
 
3.
Optionally click Show SQL to view the SQL statement.
Figure 324 
NOTE: 
You can make changes to the SQL WHERE statement on the SQL statement view, but these will not be reflected in the graphical view, which appears if you click the Show Builder button.
4.
Click Apply.
Saving and retrieving queries
If your site administrator has enabled the ability to save queries, you will notice Save and Retrieve buttons in the upper right corner of the Query Builder window.
Figure 325 
1.
2.
Click the Save button in the upper right corner of the Query Builder window.
Figure 326 
3.
Retrieving queries
If you have not logged on to OnPoint, any queries you have saved are available until you close the OnPoint web-GIS application. If you have logged on to OnPoint, any queries you have saved can be retrieved at a later time.
1.
2.
Figure 327 
3.