<?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: Select by Attributes minimum value in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/select-by-attributes-minimum-value/m-p/524853#M41138</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Andrew,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can append the elevation values to a list, sort the list, and then use the first value in the list to obtain the minimum elevation.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
list = []

fields = ["Elevation"]
with arcpy.da.SearchCursor (inputLyr, fields) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append(row[0])

list.sort()

pointMinClause = "Elevation = " + str(list[0])
arcpy.SelectLayerByAttribute_management(inputLyr, "NEW_SELECTION", pointMinClause)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 22:53:02 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2021-12-11T22:53:02Z</dc:date>
    <item>
      <title>Select by Attributes minimum value</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attributes-minimum-value/m-p/524852#M41137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a Feature Layer of points. From this feature layer, I want to select only one point: the one with the minimum Elevation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In ArcGIS I got it working with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;"Elevation "= (SELECT MAX("Elevation") FROM allpoints)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now I need to transpose this to Python. I'm trying to figure out something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;pointMinClause = '"Elevation "= (SELECT MIN("Elevation") FROM&amp;nbsp; ????
arcpy.SelectLayerByAttribute_management (inputLayer,'NEW_SELECTION',pointMinClause)
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not sure how to reference the data in the same way that I do it in ArcGIS Desktop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also may be doing the rest of that query improperly for arcpy; I'm not sure.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Oct 2013 13:36:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attributes-minimum-value/m-p/524852#M41137</guid>
      <dc:creator>AndrewBlakey1</dc:creator>
      <dc:date>2013-10-30T13:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Select by Attributes minimum value</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attributes-minimum-value/m-p/524853#M41138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Andrew,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can append the elevation values to a list, sort the list, and then use the first value in the list to obtain the minimum elevation.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
list = []

fields = ["Elevation"]
with arcpy.da.SearchCursor (inputLyr, fields) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append(row[0])

list.sort()

pointMinClause = "Elevation = " + str(list[0])
arcpy.SelectLayerByAttribute_management(inputLyr, "NEW_SELECTION", pointMinClause)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:53:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attributes-minimum-value/m-p/524853#M41138</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T22:53:02Z</dc:date>
    </item>
    <item>
      <title>Re: Select by Attributes minimum value</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attributes-minimum-value/m-p/524854#M41139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Per your question of using a subquery to do this. Something like this works to select record with the lowest (minimum) OBJECTID value in a table called 'sof'. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"OBJECTID" = (SELECT MIN("OBJECTID") FROM sof)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you are dealing with a layer or table view that already has a query on it, you would have to include that existing query in the subquery as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Some data formats (like Shapefiles for example) don't support subqueries and in that case you would have to use something like this:&lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
#Selects the record(s) that have the minimum value (assuming fieldName is numeric)
fieldName = "Elevation"
elevList = [r[0] for r in arcpy.da.SearchCursor (inputLyr, [fieldName])]
sqlExp = fieldName + " = " + str(min(elevList))
arcpy.SelectLayerByAttribute_management(inputLyr, "NEW_SELECTION", sqlExp)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:53:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attributes-minimum-value/m-p/524854#M41139</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T22:53:05Z</dc:date>
    </item>
  </channel>
</rss>

