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?

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).

0
7

Use Select by expression with this expression:

area = maximum(area, group_by:=join_label)
1
  • it works as well ! Thank you !!
    – AchB
    Aug 31, 2021 at 15:11

Your Answer

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

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