8

I created an expression with the help of the GUI in the QGIS attribute table of a vector (shapefile) layer of Native American ("Indian") reservations in the USA state of New Mexico.

"NAME" LIKE 'Picuris'

No row became selected.

The full "NAME" in the desired row is 'Picuris Indian Reservation' . I don't mind typing the whole name, but in principle, is not the LIKE function supposed to find partial matches? That is, if I want 'State Hwy 68' (which is in the FULLNAME field) (of a different layer), will the LIKE operator not find it if I use "FULLNAME" LIKE 'Hwy 68' ?

2
  • 2
    I think it is better to move your EDIT in a proper answer, (even to mark it as accepted). This way you will eliminate the actual confusion in your question, and your answer will remain as reference for the users with similar issues. Feb 27, 2014 at 5:42
  • 1
    You can also just use the "Column Filter" available in the dropdown. This creates a filter-expression LIKE %[needle]% or ILIKE %[needle]% (depending on the "case sensitive" checkbox) for you automatically. You can then use Ctrl+A to select all visible rows. Feb 27, 2014 at 7:45

3 Answers 3

11

[Posted earlier as an "edit" to my own question. Per Sorin's advice, I'm changing this to an answer instead of an edit.]

I think I may have solved it. I used a percent sign ( % ) as a "wild card" along with the LIKE operator, and it looks like I got the expected search results. Example 1: In a roads shapefile layer, "FULLNAME" LIKE '%68%' produced a selection of many roads and highways with the consecutive digits "68" in the name -- such as "State Hwy 68", "State Rte 68", "New Mexico Route 268". Example 2: In a Native American lands shapefile layer, "NAME" LIKE 'A%' produced a selection of "Acoma Indian Reservation" and "Alamo Navajo Indian Reservation".

1
  • Catlike, thank you - I was looking for this syntax so long ... :)
    – user29347
    Mar 1, 2019 at 8:18
9

You can also use the column filter of the attribute table. It works default as a 'like' expression without the % wild card.

enter image description here

Result when typing a:

enter image description here

0

I was having difficulty doing this in a filter in a layer using QGIS 3.20.1 in Select by Location Query builder. I found ILIKE worked because it matches "case-insensitive."

Now I have a filter on a layer "OWNER_FULL" = 'SCHOOL BOARD OF COUNTY' that returns 256 rows when I hit Test. But if I try "OWNER_FULL" LIKE 'school board%' I got no rows.

But when I did "OWNER_FULL" ILIKE 'school board %' I got 260 rows, so that showed me percent sign worked and the ILIKE was the best.

1
  • You get no rows with LIKE because you omitted the space between board and % ;-) Mar 20 at 11:00

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.