I have a vector layer: ROADS that is composed of different types of roads: primary, secondary, tertiary, trunk, etc.

When I right click on the layer ROADS and I go to Attribute table -> Select by expression -> the column where I want to do the selection: highway -> I wrote this:

"highway" ILIKE '%primary%' OR "highway" ILIKE '%secondary%' OR "highway" ILIKE '%tertiary%' OR "highway" ILIKE '%trunk%' NOT "highway" ILIKE '%trunk_link%' 

Till NOT "highway" ILIKE '%trunk_link%' the selection is working well. I can see all the roads that starts with primary, secondary, tertiary and trunk. So also trunk_link -> I don't want that. To erase it from the selection I add NOT "highway" ILIKE '%trunk_link%'. It didn't work -> suddenly I had O selected lines .

Do anyone knows the solution to my problem?

2 Answers 2


You need to connect the parts with AND or OR.

     "highway" ILIKE '%primary%' 
  OR "highway" ILIKE '%secondary%' 
  OR "highway" ILIKE '%tertiary%' 
  OR "highway" ILIKE '%trunk%'
AND "highway" NOT ILIKE '%trunk_link%' 
  • Perfect! Thanx a lot. Basically I made two errors: 1) instead of AND I put NOT ; 2) instead of NOT ILIKE I put just NOT. I tryied without brackets and it works too.
    – Janita
    Jun 10, 2016 at 14:57
  • You probably could also just do ... OR "highway" ILIKE 'trunk' and forget about the last bit. Jun 10, 2016 at 14:59
  • No no because I really don't want to see the the trunk_link feature. BTW I just tried to eliminate more then one feature from the selection (also secondary_link) and in that case the brackets are needed.
    – Janita
    Jun 10, 2016 at 15:18
  • 1
    Sure, if there are also other trunk% attributes you are right. In general, try to use the % only where necessary, this way you are more precise and faster. I also usually just put some extra brackets even when not strictly required because I tend to forget if AND or OR takes precedence so I make the job easier for myself in the future. Jun 10, 2016 at 16:55
  • I didn't accepted some answers? What does it mean? I didn't erase any answer..all of them are useful for me and I think that also to others with the same problem
    – Janita
    Jun 13, 2016 at 11:38

In the bottom right-hand corner of the 'select by expression' window, there is the 'select' button: pull the drop-down to reveal the 'remove from selection', 'add to selection', etc. That should do it.

  • Thanx for a quick response. I tryied but it didn't work. Already have a solution @Matthias
    – Janita
    Jun 10, 2016 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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