1

How do I select multiple features in a vector layer using the Query Builder in QGIS?

Using U.S. Census geographic data, I'm trying to select a large number of specific block groups using the GEOID feature / field.

Based on an answer found here and using the LIKE operator, I've used the following query in the Query Builder:

"GEOID" ILIKE ('34013000100%', '34013000200%')

This results in error:

OGR[3] error 1: SQL Expression Parsing Error: syntax error, unexpected ','.

I've also tried using the LIKE and IN operators; changing the wildcard from % to _ (a single underscore); and other separators replacing the comma, all with error results.

I note that filtering for a single value (such as "GEOID" ILIKE ('34013000100%') works fine.

A sample data file is found here.

2
  • Try using an IN statement: "GEOID" in ('1234', '4534', '3454', '34652') Sep 16 '20 at 16:49
  • @DPSSpatial When using the IN operator, i.e., "GEOID" IN ('34013000100%') or "GEOID" IN ('34013000100_'), QGIS returns no attributes but substituting IN with LIKE returns the expected attributes.
    – Catalyx
    Sep 16 '20 at 18:48
4

Try writing a multiple LIKE statement with the values you're trying in an IN statement.

In the image below, there are 2 sets of selected features for each LIKE statement (highlighted in pink):

"GEOID" like ('34013000100%')  
or  
"GEOID" like ('34013000200%')

enter image description here

8
  • Yes, the GEOID column is in TEXT format. The IN operator seems to work without the wildcards, i.e. if I specify the full value I'm seeking to filter. Hence, it doesn't work with "GEOID" IN ('34013000100%', '34013000200%') (or with one or more underscores) but works with "GEOID" IN ('340130001001', '340130002001'). A sample data file is here
    – Catalyx
    Sep 16 '20 at 21:42
  • @Catalyx right- you don't put the % in an IN statement... or underscores... I really don't understand what you're trying to do - select blockgroups that have a GEOID greater than a certain INTEGER value ie GEOID > 34013000100? Sep 16 '20 at 21:54
  • Pardon the confusion. I'm trying to filter a TEXT field by using wildcards. In this case, a full GEOID (in STRING format) of block groups in the referenced database has 12 characters and I know the first 11 characters that I'm looking for (i.e. up to the Census tract level). Since I don't know the last character (block group level), I'm trying to use a wildcard for the filter. I hope this better explans. If not, I can give a specific example based on the linked file.
    – Catalyx
    Sep 16 '20 at 22:31
  • @Catalyx Got it- I think - see my updated answer... let me know. Sep 16 '20 at 23:24
  • Running the filter seems to work for up to 30 values in the Query Builder's filter expression and after which it gives an error OGR[3] error 1: Too many recursion levels in expression. Do you think there is an easier way than to add the values in multiples of 30?
    – Catalyx
    Sep 17 '20 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.