1

I have a punctual shapefile containing the name of geographic locations (attribute 'name')

Using DB Manager of Qgis, I would like create an SQL query to find, within the shape, the name of a location and, and therefore its point. I would like to find the name of the location even by writing only one part.

For example: The name of location is 'Torretta'. Just writing "Torr", I would like to find all the locations that contain the word "Torr" (without considering the upper case and lower case letters).

1 Answer 1

4

One example working with QGIS Alaska dataset:

SELECT * 
FROM "airports"
WHERE lower("NAME")  LIKE lower('%Big%') 
  • FROM: your shapefile layer shown as a Virtual Layer
  • "NAME" is "name" in your case
  • '%Big%' would be '%Torr%'

enter image description here

Hitting [Load now!] button (at lower right corner), selected Big Lake and Big Mountain AFS appear as a new QueryLayer.

enter image description here

EDIT To narrow down the selection by using both "name" and "town", please add AND keyword.

SELECT * 
FROM "your_shapefile_layer"
WHERE lower("name") LIKE lower('%Torr%') AND lower("town") LIKE lower('%potenza%')
3
  • next step: in the same shape I also have an attribute "town". I would like add to quary both the search by "name" and by "town". For example: searching only the location 'Torretta' of town "potenza" Nov 19, 2017 at 10:23
  • Thanks @GiuseppeCillis Please see the bottom of my answer (marked EDIT). Please let me know if it does not work.
    – Kazuhito
    Nov 19, 2017 at 10:37
  • Yes!! It work perfectly !! Nov 20, 2017 at 20:00

Your Answer

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

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