GP tool to select greatest 1 per group

584
2
12-06-2022 08:09 AM
Labels (1)
Bud
by
Notable Contributor

Is there an OOTB geoprocessing tool that can be used to select the greatest 1 per group in a FGDB table?

For example, for a given ASSET_ID, select the road inspection that has the latest date.

Bud_0-1670342876793.png

Related:

 

0 Kudos
2 Replies
Robert_LeClair
Esri Notable Contributor

I know you mentioned you're using a fGDB but if you were using an enterprise gdb (egdb), then you could use SQL to do this.

There's an article here that explains the syntax to use - <date> = (SELECT MAX(date) FROM <table_name> GROUP BY <group_ID>)

The article does say if you create an OLE DB connection to a MS Access table then you could use the SQL syntax above.

Looking for a fGDB solution right now.

UPDATE:  It seems with Python you can do this - here's a link here that shows a labeling example.  I'm not a Python person but I suspect many on this forum are.

UPDATE 2:  For fGDB data, use the Dissolve GP tool with the Maximum value set for the Statistics Field Parameter.  That should work for you BUT it does create a new FC unfortunately.

Bud
by
Notable Contributor

Thanks!

There's an article here that explains the syntax to use - <date> = (SELECT MAX(date) FROM <table_name> GROUP BY <group_ID>)

FYI - The SQL syntax in that article appears to be incorrect: Select maximum values in Select By Attributes (greatest n per group)

Also, for my notes, the Dissolve tool doesn't seem to work for standalone tables. But the Summary Statistics tool does.