<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: To select a record based on the highest value  of a field? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337917#M26519</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I think I am getting there but still getting an error for the first line. Do&amp;nbsp; you see anything wrong on the first line?&amp;nbsp; Thanks!!!!&lt;BR /&gt;I am getting this error:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Error Info:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;type 'exceptions.RuntimeError'&amp;gt;: ERROR 999999: Error executing function.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
 maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID&amp;nbsp; A").next().getValue("OID")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("Counties",&amp;nbsp; "NEW_SELECTION", maxValue)
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = int(arcpy.GetCount_management("Stewardship").getOutput(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(result)
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Got a fire going in a few minutes, so I'll have to try to get back to previous posts later, but it seems you are on the right track.&amp;nbsp; However, will need to make a feature layer before selection as selectbyatt can't utilize a FC directly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As far as the error, probably your OID field name, it can't be both.&amp;nbsp; you are sorting on OBJECTID, but trying to extract a value from OID.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 15:59:59 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2021-12-11T15:59:59Z</dc:date>
    <item>
      <title>To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337909#M26511</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is there a way to select a record based on the highest value&amp;nbsp; of a field? And also is there a way to check if a record is selected based on the highest value before I update a record? Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jul 2013 13:17:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337909#M26511</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-07-09T13:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337910#M26512</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Is there a way to select a record based on the highest value&amp;nbsp; of a field? And also is there a way to check if a record is selected based on the highest value before I update a record? Thanks&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't have a specific example to show, but I can think of a few ways to go:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Summary Statistics usage.&amp;nbsp; This would require you to output a table to some location, then you could grab the max value for the field you are summarizing on.&amp;nbsp; Probably not best for an in-memory workflow though.&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00080000001z000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//00080000001z000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. You could convert your fc/table to a numpy array and then derive the the max value from the array.&amp;nbsp; This may be your most direct approach and can be done without writing anything to disk.&amp;nbsp; Look at the code sample in the link as it shows a very simplified way to get your statistic (you could just set a variable to your max value then use it later in your updateCursor).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//018w00000015000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//018w00000015000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3. I suppose you could also just create a basic list of values from your field you want to summarize the max value for and set this to a variable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd probably opt for the #2nd option myself.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;j&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jul 2013 13:39:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337910#M26512</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-07-09T13:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337911#M26513</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You could use a cursor with a sort on it:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;infc = my input feature class&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;myField = field I am after the max value from&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;OID = ObjectID field of my FC.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
maxValue = arcpy.SearchCursor(infc, "", "", "", myField+ " D").next().getValue(OID) 

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;change the myField field to the one you want the max value from and grab the "OID" of that record as maxValue variable.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;this would give you the values, could then use that to select by.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:59:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337911#M26513</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-11T15:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337912#M26514</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You could use a cursor with a sort on it:&lt;BR /&gt; &lt;BR /&gt;infc = my input feature class&lt;BR /&gt;myField = field I am after the max value from&lt;BR /&gt;OID = ObjectID field of my FC.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;maxValue = arcpy.SearchCursor(infc, "", "", "", myField+ " D").next().getValue(OID)&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;change the myField field to the one you want the max value from and grab the "OID" of that record as maxValue variable.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;this would give you the values, could then use that to select by.&lt;BR /&gt;&lt;BR /&gt;R_&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NICE!!! I will def use this one, Rhett.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jul 2013 16:32:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337912#M26514</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-07-09T16:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337913#M26515</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Basically, it is just sorting the table decending by myField, then grabbing the "first" row.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Change the " D" to " A" and will sort ascending and would grab the minimum value instead.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jul 2013 16:36:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337913#M26515</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2013-07-09T16:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337914#M26516</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Rhett, so if I want to update something after the search cursor, what do I do. I tried to update a field but of course it did not work, so in this example, what should I change? Thank you so much !!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp; maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID&amp;nbsp; A").next().getValue("OBJECTID")
&amp;nbsp;&amp;nbsp;&amp;nbsp; with maxValue as rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # row comes back as a tuple in the order specified here, so Office is row[0], Forester is row[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yearonly = DateStart[5:9]

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0] = yearonly


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:59:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337914#M26516</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2021-12-11T15:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337915#M26517</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Rhett, how can I run any process after I create the search cursor, because right now the cursor is pointing to an integer object (OBJECTID), but how can I select this value with the highest OBJECTID and use in a process? Right now what I have below is not going to work because it is going to look at the records and not only the one with the highest OBJECTID&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you!!!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp; maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID&amp;nbsp; A")
&amp;nbsp;&amp;nbsp;&amp;nbsp; for srow in maxValue:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = int(arcpy.GetCount_management("Stewardship").getOutput(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(result)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:59:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337915#M26517</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2021-12-11T15:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337916#M26518</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think I am getting there but still getting an error for the first line. Do&amp;nbsp; you see anything wrong on the first line?&amp;nbsp; Thanks!!!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am getting this error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Error Info:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;type 'exceptions.RuntimeError'&amp;gt;: ERROR 999999: Error executing function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
 maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID&amp;nbsp; A").next().getValue("OID")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("Counties",&amp;nbsp; "NEW_SELECTION", maxValue)
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = int(arcpy.GetCount_management("Stewardship").getOutput(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(result)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:59:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337916#M26518</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2021-12-11T15:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337917#M26519</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I think I am getting there but still getting an error for the first line. Do&amp;nbsp; you see anything wrong on the first line?&amp;nbsp; Thanks!!!!&lt;BR /&gt;I am getting this error:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Error Info:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;type 'exceptions.RuntimeError'&amp;gt;: ERROR 999999: Error executing function.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
 maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID&amp;nbsp; A").next().getValue("OID")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("Counties",&amp;nbsp; "NEW_SELECTION", maxValue)
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = int(arcpy.GetCount_management("Stewardship").getOutput(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(result)
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Got a fire going in a few minutes, so I'll have to try to get back to previous posts later, but it seems you are on the right track.&amp;nbsp; However, will need to make a feature layer before selection as selectbyatt can't utilize a FC directly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As far as the error, probably your OID field name, it can't be both.&amp;nbsp; you are sorting on OBJECTID, but trying to extract a value from OID.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:59:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337917#M26519</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-11T15:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337918#M26520</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.UpdateCursor("Stewardship", "", "", "", "OBJECTID&amp;nbsp; A")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.yearonly = DateStart[5:9]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;another quick thought before I run, UpdateCursor supports the sort also, might try something like above and see if it works correctly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is how I define row(s) values without having to actually iterate through the cursor.&amp;nbsp; Of course, you need to have a field in Stewardship FC named "yearonly".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Should update the field "yearonly" to the value in stored in the variable DateStart[5:9].&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Of course, I noticed that the " D" was changed to " A", so this should actually grab the minimum value, not the max.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:00:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337918#M26520</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-11T16:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337919#M26521</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Fire got put out before I made it.&amp;nbsp; :DIf you don't just need to update, but actually need a "selection" to use in a process, this is the line of thought I was thinking:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

minValue = arcpy.SearchCursor("Stewardship", "", "", "", "OID&amp;nbsp; A").next().getValue("OID")

arcpy.MakeFeatureLayer_management ("Stewardship", "feat_layer")


arcpy.SelectLayerByAttribute_management ("feat_layer", "NEW_SELECTION", " [OID] = " + maxValue)

Whatever you do now on "feat"layer" will honor the selection if that tool supports it.

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This one I changed to minValue since we are sorting Ascending so would get the min as the first row.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:00:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337919#M26521</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-11T16:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337920#M26522</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have OBJECTID, not OID, however when I try your code it prints always the first record. I tried both with A and D. I tried sorting by SequenceNumber (numbers from 1 to 8), and I tried sorting by OBJECTID. Which I get is always the first number. So for example, SequenceNumber 1 I get OBJECTID 2451 (object id for sequence number 1) and if I sort by OBJECTID, I get 2445, no matter what (the objectids go from 2445 to 2451). I am using SQL feature class. Any idea why this is happening? Also, you mentioned you can't do anything with a fc for a selection. Is that the same with a selection by location? Because I was able to select by location just using the fc name ("Stewardship), without creating a feature layer. Would you know why that worked? Thank you!!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID&amp;nbsp; D").next().getValue("OBJECTID")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(maxValue)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:00:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337920#M26522</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2021-12-11T16:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337921#M26523</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You could use a cursor with a sort on it:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
infc = my input feature class
myField = field I am after the max value from
OID = ObjectID field of my FC.



[maxValue = arcpy.SearchCursor(infc, "", "", "", myField+ " D").next().getValue(OID)

change the myField field to the one you want the max value from and grab the "OID" of that record as maxValue variable. &lt;/PRE&gt;this would give you the values, could then use that to select by.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ionara,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In my original posting of this code, I have the myField+" D" section that you have changed to the OBJECTID field.&amp;nbsp; This is the field that it is sorting on, so using the OID field, will get you the first (+ " A") or last (+ " D") record in the table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you are trying to find a max or min value of a particular field, you need to have that field set as the sort field.&amp;nbsp; " D" sorts the table by field and would put the largest value as the first row.&amp;nbsp; The .next() grabs the next (in this case the first) row, that being sorted descending, is the max.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:00:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337921#M26523</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-11T16:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337922#M26524</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I have OBJECTID, not OID, however when I try your code it prints always the first record. I tried both with A and D. I tried sorting by SequenceNumber (numbers from 1 to 8), and I tried sorting by OBJECTID. Which I get is always the first number. So for example, SequenceNumber 1 I get OBJECTID 2451 (object id for sequence number 1) and if I sort by OBJECTID, I get 2445, no matter what (the objectids go from 2445 to 2451). I am using SQL feature class. Any idea why this is happening? Also, you mentioned you can't do anything with a fc for a selection. Is that the same with a selection by location? Because I was able to select by location just using the fc name ("Stewardship), without creating a feature layer. Would you know why that worked? Thank you!!!&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID&amp;nbsp; D").next().getValue("OBJECTID")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(maxValue)
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, the select by location needs a feature layer also.&amp;nbsp; For you to be able to create a selection directly on the FC, I would assume that you are running from within ArcMap.&amp;nbsp; If this is the case, ArcMap "secretly" and "silently" converts FC's in the TOC to a feature layer that can be used for input to the tools.&amp;nbsp; if a feature layer is needed, and you choose the dropdown list in the tool to select the FC, the visible FC's are actually an on the fly feature layer.&amp;nbsp; So, I guess if this is always run from within ArcMap, you woulnd't need that step as it is done for you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Of course, if you export that script/model to python, it doesn't do this part for you and you need to add in the make feature or the script will error out.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:00:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337922#M26524</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-11T16:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337923#M26525</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am actually running the script I am writing so I am not directly using the tool. Not sure why it works.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jul 2013 20:32:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337923#M26525</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-07-09T20:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337924#M26526</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I have OBJECTID, not OID, however when I try your code it prints always the first record. I tried both with A and D. I tried sorting by SequenceNumber (numbers from 1 to 8), and I tried sorting by OBJECTID. Which I get is always the first number. So for example, SequenceNumber 1 I get OBJECTID 2451 (object id for sequence number 1) and if I sort by OBJECTID, I get 2445, no matter what (the objectids go from 2445 to 2451). I am using SQL feature class. Any idea why this is happening? Also, you mentioned you can't do anything with a fc for a selection. Is that the same with a selection by location? Because I was able to select by location just using the fc name ("Stewardship), without creating a feature layer. Would you know why that worked? Thank you!!!&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID&amp;nbsp; D").next().getValue("OBJECTID")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(maxValue)
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ionara,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Well, this was a little confusing as I get the same result each time I run the script also, unless I type it directly into the console.&amp;nbsp; If I type it in, I get the max and min numbers.&amp;nbsp; If I run the code, I get the min number each time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Turns out there is a copy/paste/formatting issues somewhere.&amp;nbsp; the "OBJECTID&amp;nbsp; D" should have a space in between the "OBJECTID" and the "D". However, it appears as if there is a tab character there, so it is getting ignored in the cursor so the table is sorted by default (OID Ascending).&amp;nbsp; Once I put a space in there as expected, it successfully gets both the max and min.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
maxValue = arcpy.SearchCursor(infc, "", "", "", "OBJECTID D").next().getValue("OBJECTID")
max Value =&amp;nbsp; 2110
minValue = arcpy.SearchCursor(infc, "", "", "", "OBJECTID A").next().getValue("OBJECTID")
min Value =&amp;nbsp; 1
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:00:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337924#M26526</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-11T16:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337925#M26527</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am still getting the same value. So dumb question here: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID&amp;nbsp; A").next().getValue("OID")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And you have:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[maxValue = arcpy.SearchCursor(infc, "", "", "", myField+ " D").next().getValue(OID)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I doing the sorting correctly, because you have the name of field and a plus sign, then the D in parentheses. Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jul 2013 20:35:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337925#M26527</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-07-09T20:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337926#M26528</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Rhett, Please disregard my dumb question &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It was really the problem with the tab! It is working great! I will post another thread if I have any more questions about the updating of rows using this type of selection! Thank you so much! You rock!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jul 2013 20:42:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337926#M26528</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-07-09T20:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337927#M26529</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I am actually running the script I am writing so I am not directly using the tool. Not sure why it works.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you running in the python window in ArcMap/Catalog or actually in the IDE or command window?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I try to run on a FC in the IDE (stand alone without ArcCrap) I get this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
ExecuteError: Failed to execute. Parameters are not valid.
&lt;STRONG&gt;The value cannot be a feature class&lt;/STRONG&gt;
ERROR 000840: The value is not a Raster Layer.
ERROR 000840: The value is not a Mosaic Layer.
Failed to execute (SelectLayerByAttribute).
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Once I use a feature layer, it works fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:00:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337927#M26529</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-11T16:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: To select a record based on the highest value  of a field?</title>
      <link>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337928#M26530</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I created a toolbox and added the script and I am running from there, when I click on the script.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jul 2013 20:43:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/to-select-a-record-based-on-the-highest-value-nbsp/m-p/337928#M26530</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-07-09T20:43:42Z</dc:date>
    </item>
  </channel>
</rss>

