3

For creating a legend of a map, I need to get a list of unique values over multiple attribute columns of a layer. I know how to get a list of unique values within one column - is it possible to get a list of unique values over multiple columns?

Example:
Polygon 1: Field 1: x, Field 2: a, Field 3: b

Polygon 2: Field 1: a, Field 2: c, Field 3: z

Polygon 3: Field 1: x, Field 2: b, Field 3: z

Now I need a list with the values that are unique over the fields 1, 2 and 3. For the example that would be x, a, b, c, z.

I am using QGIS Version 2.14.1

1
  • I think it would be useful to see how you are getting the unique values in one field. The process is simple using python sets. How are your python skills?
    – Fezter
    Mar 16, 2017 at 22:33

1 Answer 1

1

Your test data (layer name: Polygon):

enter image description here

If a Virtual Layer is acceptable, the syntax would be:

SELECT Distinct(Field_1) AS Field FROM Polygon
UNION
SELECT Distinct(Field_2) AS Field FROM Polygon
UNION
SELECT Distinct(Field_3) AS Field FROM Polygon
ORDER BY Field DESC

Then output would be:

enter image description here

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.