[GIS] Select features using an expression, QGIS

qgisselect-by-attribute

I've a problem when using Select features using an expression. I've an attribute table with many features: It's a shapefile from a previous CSV table. The data are localities for water analysis, where several parameters appear. But I only want few of those locations.

What I do is:in Attribute table, I open Select by Expression, Then in Fields and Values, I select my column of interest "Parameters", and from Load Values- All Unique button, I choose the names I want to pick : alfa- hexaclorociclohexano, beta-hexaclorociclohexano, gamma-hexaclorociclohexano.

The expression I use is:

"Parametro"  =  'alfa-Hexaclorociclohexano'  +   'beta-Hexaclorociclohexano'  +  'delta-Hexaclorociclohexano'  +  'gamma-Hexaclorociclohexano'

But I can't select my values… If I just pick every value independently, i.e.: 'alfa-Hexaclorociclohexano', they are selected. Then, what my problem can be ?, should I not use the + symbol ? I also tried with the And symbol, but it's not working either. Should I try another option like the Query Builder ?

Select by Expression seemed the easier option to me but I'm not able to continue.

select by expression

Best Answer

There are two possibilities when you want to select several value.

The first is to use the OR operator :

"Parametro" = 'alfa-Hexaclorociclohexano' OR "Parametro" = 'beta-Hexaclorociclohexano' OR "Parametro" = 'delta-Hexaclorociclohexano' OR "Parametro" = 'gamma-Hexaclorociclohexano'

You need to repeat the field name each time (this also work if you want to use several field)

The second is to use the IN operator :

"Parametro" IN ('alfa-Hexaclorociclohexano','beta-Hexaclorociclohexano','delta-Hexaclorociclohexano','gamma-Hexaclorociclohexano')

Work only for one field but easier to read and type (of course if you need two or more field you can join several with AND or OR...)

Related Question