Querying by Attributes

This tutorial covers selecting (or querying) features in a dataset based on their attribute values through two tools: Select Features by Value and Select Features by Expression.

Included in this tutorial:

  • The Select Features by Value tool, with demonstrations of selecting by qualitative and qualitative values 

  • Accessing the Select Features by Expression tool

Software version in examples: QGIS-LTR 3.40.5-Bratislava

Tutorial Data: The tutorial includes demonstration with sample data available here.

Credits: Sally Kaye and L. Meisterlin (2025)

The options for selecting features for qualitative and quantitative attributes are demonstrated with examples.

 

Select Features by Value

In the Layers Panel, select the name of the layer from which to make selections. Access the Select Features by Value dialogue box by clicking the icon in the Selection Toolbar. 

The dialogue box displays all fields in the selected dataset. You can scroll up and down to view all fields in the box.

accessing the Select Features by Value dialogue box

Tip: You can find the same dialogue box by clicking the funnel icon in the Selection Toolbar in the Attribute Table to Select/filter features using form

By default, all fields in the attribute table are “excluded” from a selection to begin. (In other words, none of the layer’s attributes are currently used to select features.)

You may notice that the options available as selection criteria vary based on the data type of each field in the layer’s attribute table. Qualitative and quantitative fields present different options. The sections below include examples of each type. 

Selecting by qualitative values

The selection criteria options for qualitative attributes are predictably relevant to string or text fields. These include querying based on the specific sequence of text included in the values, such as matching a value (“equal to”) or querying for values that “start with” or “end with” certain text. You will also notice that qualitative (text/string) fields also have the additional “Case Sensitive” criterion option, which is not applicable to numeric data.

The example below demonstrates selecting all features from the layer called Points1_Table1_Join with values of “A” in the “Type_AB” field; in other words, Type_AB = A.

Click the dropdown menu currently labeled Exclude Field next to the field you would like to select features from (in our example, Type_AB). To pick all features where Type_AB is equal to a given value, choose Equal to (=) from the menu. In the text box next to the selected field, type the relevant attribute value for the selection; in our case, “A”. For demonstration purposes, we are not concerned with the Case Sensitive option.

To complete the selection, click Select Features. Selected features will appear highlighted in both the map canvas and attribute table. A bar at the top of the map canvas will display how many total features have been selected.

Click Close to close the dialogue box and return to the map canvas. 

making a selection with qualitative values

Selecting by quantitative values 

The selection criteria options for quantitative attributes are those more relevant to numeric data fields. These include querying based on relative value–for example, selecting values greater than or less than a threshold value.

The example below demonstrates selecting features where, both, values in the “Int_lrg” field are less than 100 (lnt_lrg) and values in the “Int_sm” field are not equal to 5 (Int_sm ≠ 5).

Click the Exclude Field dropdown menu next to the Int_lrg field and select Less than (<). In the corresponding text box, type “100.”

Repeat, selecting Not equal to () next to the Int_sm field and typing “5” into the text box.

You can create parameters from as many fields as you would like before choosing Select Features to select all features that fit the selection criteria.

making a selection with multiple quantitative criteria

Selecting by multiple parameters in the same field (“or”)

The quantitative example above demonstrated a compound query where two criteria from different fields are satisfied. In this example, we will demonstrate selecting features that satisfy either of two criteria from the same field. Specifically, we will select features with either a value of A or a value of B in the Type_AB field. (This will ultimately select all features in the sample dataset.)

Select all features where Type_AB = A as described above under Selecting by qualitative values.

Then, return to the text box next to the Type_AB field, delete A and replace the value with B.

Click the dropdown arrow next to Select Features at the bottom of the dialogue box and select Add to Current Selection. This will keep the selected features from the previous selection and add the new selection (in our example, all features are selected, because all features have a Type_AB value of either A or B).

Click Close to close the dialogue box and return to the map canvas. 

adding to selection


Select Features by Expression

More complex selections by value (using expressions) can be made with the Select Features by Expression tool. In the Layers Panel, select the name of the layer from which to make selections. Access the tool by clicking the arrow next to the Select Features by Value icon and choosing from the dropdown menu.

In the demonstration below, we show the basic outline of the dialogue box for this tool, but do not make any selections. 

Under the Expression tab, you can type directly into the text box and/or use a number of provided building blocks. 

  • The central panel of the Select Features by Expression dialogue box includes functions, operators, and values you can use to build your expression. Most of these are accessed by expanding their headings within the panel. 

    • Any of these can be added to the expression text field by double-clicking on their name in the list. 

    • For example, you can call upon the values within any field of the input attribute table under the Fields and Values heading (expanding this heading is demonstrated below). 

  • Beneath the Expression text box is a small collection of the most common, familiar operator buttons. These include = equality, + addition, - subtraction, / division, and * multiplication, as well as others. You can click each of these to add the operator to your expression.

The Function Editor tab allows you to use Python to create a more complex expression, if needed. 

accessing the Select Features by Expression tool

 
Previous
Previous

Single Symbols for Vectors

Next
Next

Querying based on Spatial Relationships