I saw a lot of posts about how you select maximum value in the particular field and I've been trying to use that query in a python code, but none of the posts really helped me solve my problem. There is a problem that I always get an error saying that I have an invalid expression.
I've been using:
arcpy.Select_analysis (input_layer, output_layer,"Shape_Area = (SELECT MAX( Shape_Area)" FROM layer_name)
I'm so confused as this query sometimes works and sometimes not, even in the attribute table or if I'm trying to use a tool Select, Table Select etc.
Can anyone help me? Or is it there some other way how to identify the maximum value in the field.
Best Answer
Have you seen SQL reference for query expressions used in ArcGIS, subqueries section?. Depending on your data not all queries are supported:
It could explain why it sometimes works for you if you have different inputs.
You can do it without using ArcGIS selection tools if that is an option for you. This will find max value in a specified column and print out ObjectID:
The objectid can of course be passed on to Select By Attributes if you want to select the row: