I've set up a Model in ArcGIS ModelBuilder (ArcMap 10.6) which select some rows of table "Rivers". Then i want to select the River with the Max-Value of Field "Diff" out of the selected Rows (not the whole Dataset). I tried to use "Select Layer by Attribute" with the following Expression

"Diff"= (Select MAX("Diff") FROM "Rivers")

it looks like the subquery selects "MAX" from the whole Dataset and not from my selection.

How do I extract the Max-Value from my selection?

  • The table is a shapefile, file geodatabase or what format? See: desktop.arcgis.com/en/arcmap/10.3/map/working-with-layers/…
    – BERA
    Nov 25, 2021 at 12:57
  • I've come across this issue before, I don't believe the subquery honours a selection. You need to export your selection to a temporary dataset in the same workspace then subquery that.
    – Hornbydd
    Nov 25, 2021 at 15:21
  • The table is a Feature Layer in a File Geodatabase so Subquery is already running, but not just on the selection. My problem with an export is that i need this subquery in a model, so it would produce 20'000 datasets
    – GISDani
    Nov 25, 2021 at 16:05
  • Why would exporting a selection create 20,000 datasets? Did you mean 20,000 rows in a single dataset?
    – Hornbydd
    Nov 25, 2021 at 16:35
  • I have to process 20'000 different selections, on every selection will the subquery run
    – GISDani
    Nov 25, 2021 at 19:38

2 Answers 2


In your "Select Layer by Attribute" for your sub_query change the Selection type parameter to SUBSET_SELECTIONSUBSET_SELECTION


Thanks for your answers. I've learn't that a subquery can't handle a predefined selection. I solved it now with a little script that calculates the max-Value separately and use this value as a parameter in the main-query. So both querys can deal with the preselection and it runs.

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.