User Tools

Site Tools


guide:help:mnuselectselectbyquery

Select by Query

Documentation | Help File | UI | 2D Mode | Menu | Select | Select by Query

Clicking on the Select/Select by Query menu item provides the means for selecting shapes on a vector layer based on a SQL type query performed on the attribute table. A shape is said to satisfy the query if the logical value of the query evaluates to True.

To select shapes by running an SQL query on the attributes table

  1. Activate (highlight) the vector layer on which the selection is to be performed. Do this by clicking on its name in the Legend.
  2. Click on the Select/Select by Query menu item - this invokes the Select by Query dialog box.
  3. Within the Select by Query dialog box construct the SQL type query - see the Constructing SQL type query instructions below.
  4. Choose the selection result from the drop-down list beside the Execute button - see Selection results below.
  5. Click on the Execute button - all shapes satisfying the current query will be selected.
  6. [OPTIONAL] To perform a subquery or a different query repeat the steps from 2 to 4.
  7. Click on the Cancel button.

Selection results

  • Replace Selection - a new selection is performed regardless of what is currently selected,
  • Add to Selection - the recent selection is preserved and the shapes that satisfy the current query are selected,
  • Subtract from Selection - from the set of recently selected shapes the shapes that do not satisfy the current query remain selected.
  • Narrow Selection - from the set of recently selected shapes the shapes that satisfy the current query remain selected.


Select by Query dialog box.

Constructing SQL type query

The SQL type query consists of comparison statements connected with logical operators in the following way:

[comparison statement] [logical operator] [comparison statement] … [logical operator] [comparison statement].

Additionally, round brackets can be used to group/prioritize a sequence within the query. The left bracket '(' must always appear before a comparison statement and the right bracket ')' after a comparison statement. The logical operators AND and OR must appear before a comparison statement/left bracket or after a comparison statement/right bracket and not at the beginning or the ending of the query. The negation operator NOT must appear after a logical operator/left bracket or at the beginning of the query. A comparison statement consists of a primary attribute, relation operator and value/secondary attribute in the following way:

[primary attribute] [relation] [value]     or     [primary attribute] [relation] [secondary attribute].

An attribute which name contains a space must be written inside the square brackets.

To add a comparison statement to the query

  1. Within the Comparison statement box choose the primary attribute from the left Attribute drop-down list.
  2. To compare the primary attribute with a value click on the Value button in the same box. To compare the primary attribute with another attribute click on the Attribute button in the same box.
  3. (A) If you have chosen Value in the previous step then a tool appropriate to the primary attribute type will appear below the Value button. If the primary attribute is of: String, Number or Float type then a text box will appear, Boolean type then a drop-down list will appear, Date type then a date picker will appear. (B) If you have chosen Attribute in the previous step then a drop-down list will appear below the Attribute button. The drop-down list will contain all the attributes of the same type as the primary attribute except the primary attribute itself.
  4. (A) Specify the value in the tool. (B) Pick the secondary attribute from the drop-down list.
  5. Choose a relation operator from the Relation drop-down list.
  6. Click on the Add button in the same box.

To add a logical operator to the query

  1. Within the Logical operator box choose logical operator from the drop-down list.
  2. Click on the Add button in the same box.

To put brackets around a desired part of the query

  1. Within the query text box move the mouse pointer to the beginning/ending of the desired part.
  2. Press and hold the left mouse button.
  3. Move the mouse pointer to the ending/beginning of the desired part.
  4. Release the left mouse button.
  5. Click on the ( ) button.

To blank the query, click on the Clear button.

Supported operators are:

  • AND
  • OR
  • NOT
  • =
  • <>
  • <
  • >
  • >=
  • +
  • -
  • *
  • /
  • %
  • BETWEEN..AND
  • IN
  • IS NULL
  • IS NOT NULL

Supported math functions are:

  • ABS()
  • ASIN()
  • ACOS()
  • ATAN()
  • CEIL()
  • COS()
  • DEGREES()
  • EXP()
  • FLOOR()
  • LN()
  • LOG()
  • LOG10()
  • PI()
  • POWER()
  • RADIANS()
  • ROUND()
  • SIN()
  • SQRT()
  • TAN()
  • TRUNC()

Supported string functions are:

  • LENGTH()
  • UPPER()
  • LOWER()
  • STRPOS()
  • SUBSTR()
  • LEFT()
  • RIGHT()
  • TRIM()

To guarantee query compatibility across different SQL servers Date should be encoded using predefined functions:

  • $date(year[,month][,date])
  • $time(hour[,minutes][,seconds][,miliseconds])
  • $datetime(year[,month][,date][,hour][,minutes][,seconds][,miliseconds])
  • $today
  • $now

Associated functions

  • To transfer the selected shapes to the temporary clipboard layer, use one of the following functions: Cut, Copy, Copy Special.
  • To remove the selected shapes from the layer, use the Delete shape feature.
  • To cancel all previously made selections, use the Deselect all feature.
  • To invert the current selection, i.e. select all not selected shapes and deselect all selected shapes in the active layer, use the Invert Selection feature.
  • To show the attributes table of a vector layer, use the Show attributes table feature.

Similar functions

Note

  • All currently selected shapes are highlighted on the Map area.
  • Values (or averages, maximal and minimal numeric values) of attributes of the selected shape (or shapes) are displayed in the Attributes tab of the Selected panel.
  • The default logical value of the SQL type query, i.e. the logical value of the empty query, is True.
  • A summary of the most recent selection operation is displayed below the query text box.
  • When the primary attribute is of String type and specifying a value for the LIKE comparison the '_' character can be used as a single unspecified character and the '%'  character as a sequence of unspecified characters.
2019/05/27 14:20

Page Tools