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

underdark
84.9k22 gold badges237 silver badges418 bronze badges
asked Jul 19, 2016 at 12:22
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? Commented 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

answered May 4, 2018 at 11:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.