QGIS – Proper Syntax for Selecting Rows

attribute-tableexpressionfields-attributesqgisselect

I have a long shapefile with various columns. I want to select only some rows, based on an expression. The column used for filtering is "binomial". I tried so far:

"binomial" = "Axis axis"
$binomial = "Axis axis"
$binomial = Axis axis

… and so on, but nothing works. After understanding this, I would like also to add more names, something such as:

$binomial = "Axis axis" and $binomial = "Dama dama"

I am not used to the coding language of QGIS (is that Python? C++?) and I cannot understand how to select those rows.

Best Answer

Try:

"binomial" = 'Axis axis'

In QGIS, double quotes " are used to reference a field. Single quotes ' are used to contain a string. No quotes for numerical values. The $ sign is used to reference a current features value, like $currentfeature, $id or $geometry. The things you can use with $ are predefined.

To filter for multiple values in the same field you should use OR rather than AND. This is because one field cannot contain two different values at the same time and AND therefore will never become True. An easier syntax than several ORs is to use IN like:

"binomial" in ('Axis axis','Dama dama')

The coding language of QGIS expressions is similar, but not identical to SQL.

Related Question