selecting maximum value of an attribute table within model builder

10185
6
04-08-2010 06:01 AM
MichaelSutherland
New Contributor
I am currently trying to automate a process within model builder that selects and extracts a new feature class based upon the maximum value from a field in the attribute table of a polygon without knowing the maximum beforehand.  i tried using the sql expression SELECT MAX("Field Name") within the select tool but it says an invalid sql expression was used.  Any thoughts?

Any help would be greatly appreciated.  Thanks in advance.
0 Kudos
6 Replies
ShitijMehta
Esri Regular Contributor
Try the expression like this with Make Feature Layer or Select tool:
"ICOUNT" = (SELECT MAX("ICount") FROM INPUT)

ICOUNT is the field that I used in my example and INPUT is the input feature class to the tool.

*This works only with feature class in a geodatabase.

See Sub Queries in the SQL Reference in this help doc:
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=SQL_Reference
MichaelSutherland
New Contributor
Thanks that seems to have worked.  Is there a way to do this with raster data?  I have raster data where I'd like to select a large connected area based upon maximum pixel values.  Although the method suggested works with polygons, I'd like to the conversion to poly if possible. 

Thanks again for your help.
0 Kudos
curtvprice
MVP Esteemed Contributor
I have raster data where I'd like to select a large connected area based upon maximum pixel values.

If you're seriously looking for a large connected area you may have to do some processing using the tool Region Group, which finds connected areas with the same raster value. Would you then want to choose the largest connected area with a maximum pixel value? Perhaps you could describe your problem with a little more detail?

0 Kudos
ShitijMehta
Esri Regular Contributor
Try Make Raster Layer tool.
0 Kudos
MichaelSutherland
New Contributor
thanks again for the response.  this tool would seemingly work, however when i verify my sql expression (which is the same expression as used above) i receive an error message stating 'an expected field was not found or could not be retrieved properly.'  it is weird because the query builder populates the menu with the attribute i would like to select.

i also receive an error when i try to manually select the max by selecting unique value (although not in the verification of the sqp expression but when the process is actually executed).

the input raster is within a file geodatabase.

any thoughts?
0 Kudos
ShitijMehta
Esri Regular Contributor
I would try something like the attached image.
Pls read more about Precondition:
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Example_of_a_precondition

and
about using inline variable substitution:
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=In-line_variable_substitution