AnsweredAssumed Answered

Select Max value arcpy

Question asked by timdunlevie on Dec 13, 2015
Latest reply on Jun 6, 2018 by andrescastillo08

Hi all,

 

I have a FC in an SDE with Fields: ID & Version.

These are populated like this:

 

ID "A", Version "1"

ID "A", Version "2"

ID "B", Version "1"

ID "B", Version "2"

etc..

 

so when the ID object changes we create a new shape with a new Version number, but keep the old shape for historic purposes.

 

I am doing a join on another table but only want to perform the join on a subset of the original FC, grabbing the latest "Version" of the ID.

For the life of me I cannot seem to be able to select these records.

 

This will be a python script.

 

I was thinking of using the arcpy.MakeFeatureLayer_management with an expression and/or arcpy.SelectLayerByAttribute_management function with an expression to form my subset before I join to another table.

 

"Version" = (SELECT MAX("Version") from FC) - does not seem to work. I also tried a "group by" and got a sql error.

 

We are using SQL server and ArcGIS 10.2

 

Even in ArcMap I cannot seem to be able to select the latest version of the ID....I am guessing I don't have the syntax correct.

 

any help would be appreciated.

 

thanks

Outcomes