5

I have a table (shapefile) in QGIS where I want to select features that satisfies this condition:

group by a field ("join_label") and within the "grouped field", pick the attribute with the highest area (the area has already been calculated in a separate field)

I tried to do this:

maximum("Area", group_by:="join_label")

This expression selects everything in the table.

I wanted to use the "Execute SQL" function but how do I write the query?

Taras
35.7k5 gold badges77 silver badges151 bronze badges
asked Aug 31, 2021 at 13:45

2 Answers 2

7

Using the Execute SQL function:

SELECT
 join_label,
 MAX("Area") as max_area,
 geometry
FROM
 input1
GROUP BY
 join_label

Not forgetting to select the layer in the Additional input datasources at the top of the tool window (which gets the name input1 in your expression).

Taras
35.7k5 gold badges77 silver badges151 bronze badges
answered Aug 31, 2021 at 14:12
0
7

Use Select by expression with this expression:

area = maximum(area, group_by:=join_label)
Taras
35.7k5 gold badges77 silver badges151 bronze badges
answered Aug 31, 2021 at 14:04
1
  • it works as well ! Thank you !! Commented Aug 31, 2021 at 15:11

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.