I have a shapefile whose features I can filter by specifying a where clause in the query dialogue. F.x. I have a field named 'city_name' and by stating 'city_name = "London"' in the where clause only London is displayed. What I would like to do now is to fetch all values in 'city_name' from the attribute table.
Something like that:
select distinct city_name from [attribute table]
I found several tools in QGIS apparently dealing with SQL and I also had a quick look at the different Plugins. But I fail at connecting to a database or the table name … what database or which table in that case?
In the end I want to export the result list and use it for further processing.
I am using QGIS 1.8.
Best Answer
Update answer (QGIS Version >= 2.14)
Since QGIS 2.14, you can use run SQL statements on any loaded vector layer using Virtual layers.
In the Create virtual layer dialog, enter you SQL statement in the Query field. Something like:
SELECT DISTINCT city_name FROM layer_name
For geometry set No Geometry
Note: this table will be updated if new values are added to the city_name column.
Legacy answer (QGIS Version < 2.14)
You have a few choices to do what you ask.
I have just noticed that, in the Vector > Analysis Tools, there is a List unique Values tool that is precisely what one needs for this task. So easy... no workarounds and no need for Plugins.