How to find the minimum and maximum values of an Object ID

9683
8
Jump to solution
05-23-2016 02:46 PM
JaromHlebasko
Occasional Contributor III

Hello, I am trying to write some Python scripts to query a REST endpoint but am not very familiar with SQL lingo. I would like to do it in the environment of the ArcGIS REST Services Directory for a particular map service layer. How would I go about finding the minimum value of the Object ID as well as the maximum value of the Object ID in the 'Where' clause? It is probably very simple so sorry for the lack of understanding.

Thanks!

0 Kudos
1 Solution

Accepted Solutions
RobWaller
New Contributor III

Not sure how to do it with 'Where Clause' but you could return the stats on the layer from the REST Query to get the min and max.

e.g.leave all blank and use this for Output Statistics

[{"statisticType":"min","onStatisticField":"objectid", "outStatisticFieldName":"MinID"},

{"statisticType":"max","onStatisticField":"objectid", "outStatisticFieldName":"MaxID"}]

example using ESRI sample server:

Query: Facilities (ID: 0)

View solution in original post

8 Replies
ChristianWells
Esri Regular Contributor

You should be able to do this via a subquery:

id = (select max(id) from table_name)

To do this, standardized queries must be set to true:

About standardized queries—Documentation (10.3 and 10.3.1) | ArcGIS for Server

0 Kudos
JaromHlebasko
Occasional Contributor III

I can’t figure out how to specify the table_name variable in the suggested subquery:

  id = (select max(id) from table_name)

and then also form the appropriate query with the subquery embedded within it. Everything I try, including the value “table_name” itself, gets me a “Cannot open table for Load” error.

Any suggestions?

0 Kudos
ChristianWells
Esri Regular Contributor

Table_name can be replaced with the actual name of the table on disk or DBMS. Are you using SDE or a FGDB here?

0 Kudos
JaromHlebasko
Occasional Contributor III

I'm actually trying to query a MapServer REST endpoint In the ArcGIS REST Services Directory. I set it up as an SDE.

0 Kudos
RobWaller
New Contributor III

Not sure how to do it with 'Where Clause' but you could return the stats on the layer from the REST Query to get the min and max.

e.g.leave all blank and use this for Output Statistics

[{"statisticType":"min","onStatisticField":"objectid", "outStatisticFieldName":"MinID"},

{"statisticType":"max","onStatisticField":"objectid", "outStatisticFieldName":"MaxID"}]

example using ESRI sample server:

Query: Facilities (ID: 0)

JaromHlebasko
Occasional Contributor III

Perfect! Worked like a charm. Thank you! Thank you!

0 Kudos
JosephRhodes2
Occasional Contributor II

Just wanted to let you know that this was a huge help to me today. Thanks!

0 Kudos
ViktoriaMagnis
New Contributor II

I was wondering if anybody is having problems using select(max) in ArcServer 10.5.  I have a 10.2 rest service that is querying a layer with this where clause "ElectionDate in (SELECT max(ElectionDate) FROM PollingPlaceHistory)" and it works fine.  But the 10.5 service using the same data will not work. 

0 Kudos