QGIS Select by Expression – Selecting First Row for Each Group Using Select by Expression in QGIS

qgisselect-by-expression

How would/could I use the select by expression tool to select only the first row for each origin_id group? The rows with a yellow border are the ones I want selected.

example selection

Best Answer

You can use:

array_first(array_agg($id,"origin_id",order_by:=$id)) = $id

You did not specify the sorting of your table so I assume you use the default order by feature id ($id). If you use another sorting, change the order_by:= part to a field you wish to sort by. For example to sort by destination_id:

array_first(array_agg($id,"origin_id",order_by:="destination_id")) = $id