<?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 How to extract top 5 records in search cursor, not in SQL server in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-extract-top-5-records-in-search-cursor-not/m-p/1232556#M66087</link>
    <description>&lt;P&gt;Hello, I am seeking a way to extract top 5 records from a sorted search cursor.&amp;nbsp;According to ESRI, we can use top for sql clause but it is only supported by SQL server. I tried range function (please see below) but it did not work unfortunately.&lt;/P&gt;&lt;P&gt;Thank you in advance for any coding advice!&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.SearchCursor(data, fieldName, sql_clause=(None,'ORDER BY IDA DESC')) as cursor:
    for i in range(5):                 
        for row in cursor:
            print("IDA value: ", row[1])&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 17 Nov 2022 01:45:03 GMT</pubDate>
    <dc:creator>Aнастасия88</dc:creator>
    <dc:date>2022-11-17T01:45:03Z</dc:date>
    <item>
      <title>How to extract top 5 records in search cursor, not in SQL server</title>
      <link>https://community.esri.com/t5/python-questions/how-to-extract-top-5-records-in-search-cursor-not/m-p/1232556#M66087</link>
      <description>&lt;P&gt;Hello, I am seeking a way to extract top 5 records from a sorted search cursor.&amp;nbsp;According to ESRI, we can use top for sql clause but it is only supported by SQL server. I tried range function (please see below) but it did not work unfortunately.&lt;/P&gt;&lt;P&gt;Thank you in advance for any coding advice!&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.SearchCursor(data, fieldName, sql_clause=(None,'ORDER BY IDA DESC')) as cursor:
    for i in range(5):                 
        for row in cursor:
            print("IDA value: ", row[1])&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 17 Nov 2022 01:45:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-extract-top-5-records-in-search-cursor-not/m-p/1232556#M66087</guid>
      <dc:creator>Aнастасия88</dc:creator>
      <dc:date>2022-11-17T01:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract top 5 records in search cursor, not in SQL server</title>
      <link>https://community.esri.com/t5/python-questions/how-to-extract-top-5-records-in-search-cursor-not/m-p/1232560#M66088</link>
      <description>&lt;LI-CODE lang="python"&gt;# assuming numeric data
# fc = your featureclass
# field = your field
a = [row[0] for row in arcpy.da.SearchCursor(fc, field)]
# assume:  a = [9, 5, 3, 2, 10, 22]

sorted(a, reverse=True)[:5]
[22, 10, 9, 5, 3]&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 17 Nov 2022 02:33:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-extract-top-5-records-in-search-cursor-not/m-p/1232560#M66088</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-11-17T02:33:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract top 5 records in search cursor, not in SQL server</title>
      <link>https://community.esri.com/t5/python-questions/how-to-extract-top-5-records-in-search-cursor-not/m-p/1232586#M66089</link>
      <description>&lt;P&gt;Thanks DanPatterson for the solution!&lt;/P&gt;&lt;P&gt;It works well&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 04:49:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-extract-top-5-records-in-search-cursor-not/m-p/1232586#M66089</guid>
      <dc:creator>Aнастасия88</dc:creator>
      <dc:date>2022-11-17T04:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract top 5 records in search cursor, not in SQL server</title>
      <link>https://community.esri.com/t5/python-questions/how-to-extract-top-5-records-in-search-cursor-not/m-p/1232714#M66101</link>
      <description>&lt;P&gt;You were close with your original code, just a couple issues:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.SearchCursor(data, fieldName, sql_clause=(None,'ORDER BY IDA DESC')) as cursor:
    for i in range(5):                 
        print("IDA value: ", next(cursor)[0])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 15:05:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-extract-top-5-records-in-search-cursor-not/m-p/1232714#M66101</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2022-11-17T15:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract top 5 records in search cursor, not in SQL server</title>
      <link>https://community.esri.com/t5/python-questions/how-to-extract-top-5-records-in-search-cursor-not/m-p/1332272#M68757</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371"&gt;@JoshuaBixby&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I apology for late reply for your solution - I have realized your message just now.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kudos for your solution as well&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 06:21:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-extract-top-5-records-in-search-cursor-not/m-p/1332272#M68757</guid>
      <dc:creator>Aнастасия88</dc:creator>
      <dc:date>2023-09-26T06:21:56Z</dc:date>
    </item>
  </channel>
</rss>

