<?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: using join by in arcpy.da.searchcursor() - what is the right syntax? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642207#M50060</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You cannot use '*' when using sql_clause. You must specify each field explicitly.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;OK, I GOT IT (I THINK). The same fields should be in the "group-by" part and in the "fields" part.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;THANK YOU JAMES, THANK YOU MATHEW&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it is very confusing, and the ObjectID part is weird, I wouldn't have got it on my own in a million years. Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 08 Apr 2014 15:02:03 GMT</pubDate>
    <dc:creator>yonatanrubinstein</dc:creator>
    <dc:date>2014-04-08T15:02:03Z</dc:date>
    <item>
      <title>using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642191#M50044</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, I'm trying to run a code that uses a "join by statement" inside a searchcursor (it was done to imitate the join by inside the iterate features tool in the modelbuilder). I've tried this code (as a trial before implementing it on the real script), but I can't seem to find the right syntax or any documentation. &lt;/SPAN&gt;&lt;PRE class="plain" name="code"&gt;import arcpy&amp;nbsp; fc = "D:\\Projects\\proj1\\SumsOfRoutes.gdb\\all_routes_1stBatch" field = "r_Identity" field2 = "Shape_Length" ##sql = "(None, 'GROUP BY \"r_Identity\"')" sql = "(None,'Group BY r_Identity')"&amp;nbsp;&amp;nbsp; fields=["*"] cursor = arcpy.da.SearchCursor(fc,fields,sql_clause=sql)&amp;nbsp;&amp;nbsp; # print r_Identity and Shape_Length of each feature in feature class for row in cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp; print(str(int(row.getValue(field))) + ":&amp;nbsp; " + str(row.getValue(field2)) + " meters")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anybody know how it should be written?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT: for the script above, I get the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;TypeError: 'sql_clause' should be sequense of 2 strings(prefix, postfix)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Apr 2014 13:22:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642191#M50044</guid>
      <dc:creator>yonatanrubinstein</dc:creator>
      <dc:date>2014-04-08T13:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642192#M50045</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Yonatan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think sql_clause needs to be passed as a tuple. Try removing the quotes:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;sql = (None,'GROUP BY r_Identity')&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;On a side note, you could probably increase the efficiency of your script by only pulling the fields you need for the da.SearchCursor. Like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;fields=[field,field2]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let me know how it goes!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Apr 2014 13:41:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642192#M50045</guid>
      <dc:creator>JoshuaChisholm</dc:creator>
      <dc:date>2014-04-08T13:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642193#M50046</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here's my guess...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Change:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
sql = (None,'GROUP BY r_Identity')
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
sql = [None,"GROUP BY r_Identity"]
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:17:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642193#M50046</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-12T03:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642194#M50047</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Joshua,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the quick response.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. As far as I Know, the sql_clause is a string. As evidence, when I do as you suggested and write &lt;/SPAN&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;sql = (None,'GROUP BY r_Identity')&lt;/PRE&gt;&lt;SPAN&gt; I get the following error: &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;TypeError: 'where_clause' is not a string&lt;/PRE&gt;&lt;SPAN&gt;, so that is why I have the quotation marks. Any Ideas?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. I know listing only 2 fields will&amp;nbsp; increase the efficiency of the cursor, but will it enable me to use other field in the layer, later on?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Apr 2014 13:59:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642194#M50047</guid>
      <dc:creator>yonatanrubinstein</dc:creator>
      <dc:date>2014-04-08T13:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642195#M50048</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I just noticed you have this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;fields=["*"]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is not allowable in a GROUP BY statement.&amp;nbsp; That is, you could not write it as:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;SELECT * &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FROM table1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;GROUP BY table1.field1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You must specify the fields you wish to include in the group by too!!!&amp;nbsp; Like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;SELECT table1.field1, table1.field2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FROM table1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;GROUP BY table1.field1, table1.field2&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Apr 2014 14:04:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642195#M50048</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2014-04-08T14:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642196#M50049</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Update:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This must be a bug or something because I don't see how this can be correct.&amp;nbsp; According to Shaun's reply in this thread: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://forums.arcgis.com/threads/77876-Group-By-functionality-of-da.cursors-sql_clause" rel="nofollow" target="_blank"&gt;http://forums.arcgis.com/threads/77876-Group-By-functionality-of-da.cursors-sql_clause&lt;/A&gt;&lt;SPAN&gt; the suggestion is to include the "ObjectID" field in the group by clause to overcome the error you are experiencing.&amp;nbsp; Here's my working code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; fc = r'H:\Documents\ArcGIS\Default.gdb\RainGauges' fields = ('Data_Type')&amp;nbsp; sql=[None, "GROUP BY Data_Type, ObjectID"] cursor = arcpy.da.SearchCursor(fc, fields,sql_clause=sql)&amp;nbsp; for row in cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0] &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;HOWEVER, this completely defeats the ability to actually group rows because the ObjectID is a unique value!!&amp;nbsp; lol...&amp;nbsp; Maybe I am simply misunderstanding here, but that is exactly what is happening in my test data.&amp;nbsp; That is, it doesn't matter if real/actual groups exist in my select fields, they will NEVER group correctly because I must include the ObjectID in the group by clause (it is unique values).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am happy to be corrected on this one!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Apr 2014 14:19:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642196#M50049</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2014-04-08T14:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642197#M50050</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;OK, James, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to rewrite the script by your 2 suggestions: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

fc = "D:\\Projects\\proj1\\SumsOfRoutes.gdb\\all_routes_1stBatch"
field1 = "r_Identity"
field2 = "Shape_Length"

sql = [None,'Group BY r_Identity']


fields=[field1,field2]
cursor = arcpy.da.SearchCursor(fc,fields,sql_clause=sql)


# print r_Identity and Shape_Length of each feature in feature class
for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(row) &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;RuntimeError: An invalid SQL stament was used. [SELECT r_Identity, Shape_Length, OBJECTID FROM all_routes_1stBatch GROUP BY r_Identity] &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any Ideas as to what's wrong?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and the question I asked Joshua:&amp;nbsp; I know listing only 2 fields will increase the efficiency of the cursor, but will it enable me to use other fields in the layer later on?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:17:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642197#M50050</guid>
      <dc:creator>yonatanrubinstein</dc:creator>
      <dc:date>2021-12-12T03:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642198#M50051</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;OK, James, &lt;BR /&gt;&lt;BR /&gt;I tried to rewrite the script by your 2 suggestions: &lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

fc = "D:\\Projects\\proj1\\SumsOfRoutes.gdb\\all_routes_1stBatch"
field1 = "r_Identity"
field2 = "Shape_Length"

sql = [None,'Group BY r_Identity']


fields=[field1,field2]
cursor = arcpy.da.SearchCursor(fc,fields,sql_clause=sql)


# print r_Identity and Shape_Length of each feature in feature class
for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(row) &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;I get the following error:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;RuntimeError: An invalid SQL stament was used. [SELECT r_Identity, &lt;STRONG&gt;Shape_Length&lt;/STRONG&gt;, OBJECTID FROM all_routes_1stBatch GROUP BY r_Identity] &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Any Ideas as to what's wrong?&lt;BR /&gt;&lt;BR /&gt;and the question I asked Joshua:&amp;nbsp; I know listing only 2 fields will increase the efficiency of the cursor, but will it enable me to use other fields in the layer later on?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You cannot include Shape_Length (see bold above) in your select because it is not included in your GROUP BY portion.&amp;nbsp; Remove it and see if it at least completes without error.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:17:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642198#M50051</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-12T03:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642199#M50052</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Update:&lt;BR /&gt;&lt;BR /&gt;This must be a bug or something because I don't see how this can be correct.&amp;nbsp; According to Shaun's reply in this thread: &lt;A href="http://forums.arcgis.com/threads/77876-Group-By-functionality-of-da.cursors-sql_clause" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/77876-Group-By-functionality-of-da.cursors-sql_clause&lt;/A&gt; the suggestion is to include the "ObjectID" field in the group by clause to overcome the error you are experiencing.&amp;nbsp; Here's my working code:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

fc = r'H:\Documents\ArcGIS\Default.gdb\RainGauges'
fields = ('Data_Type') 
sql=[None, "GROUP BY Data_Type, ObjectID"]
cursor = arcpy.da.SearchCursor(fc, fields,sql_clause=sql)

for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0]

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;HOWEVER, this completely defeats the ability to actually group rows because the ObjectID is a unique value!!&amp;nbsp; lol...&amp;nbsp; Maybe I am simply misunderstanding here, but that is exactly what is happening in my test data.&amp;nbsp; That is, it doesn't matter if real/actual groups exist in my select fields, they will NEVER group correctly because I must include the ObjectID in the group by clause (it is unique values).&lt;BR /&gt;&lt;BR /&gt;I am happy to be corrected on this one!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I get the same runtimeerror as before... &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:17:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642199#M50052</guid>
      <dc:creator>yonatanrubinstein</dc:creator>
      <dc:date>2021-12-12T03:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642200#M50053</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I get the same runtimeerror as before... &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Is "r_Identity" the actual field name?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Make sure the spellng is correct. I get the same error in my working example if it is incorrectly spelled.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Apr 2014 14:28:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642200#M50053</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2014-04-08T14:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642201#M50054</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You must list all fields that will be included in the sql_clause parameter in the fields parameter.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = r'H:\Documents\ArcGIS\Default.gdb\RainGauges'
fields = ('Data_Type', 'ObjectID')
sql=[None, "GROUP BY Data_Type, ObjectID"]
cursor = arcpy.da.SearchCursor(fc, fields,sql_clause=sql)

for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0]&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:17:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642201#M50054</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-12T03:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642202#M50055</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You must list all fields that will be included in the sql_clause parameter in the fields parameter.&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = r'H:\Documents\ArcGIS\Default.gdb\RainGauges'
fields = ('Data_Type', 'ObjectID')
sql=[None, "GROUP BY Data_Type, ObjectID"]
cursor = arcpy.da.SearchCursor(fc, fields,sql_clause=sql)

for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0]&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Matthew,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am still not understanding how this will correctly perform any GROUP BY because of the requirement include the unique values in ObjectID field.&amp;nbsp; How is this ever going to group on the target fields????&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:17:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642202#M50055</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-12T03:17:29Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642203#M50056</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You are right I was using ORDER BY.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Apr 2014 14:34:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642203#M50056</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2014-04-08T14:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642204#M50057</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You cannot include Shape_Length (see bold above) in your select because it is not included in your GROUP BY portion.&amp;nbsp; Remove it and see if it at least completes without error.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;OK, &lt;/SPAN&gt;&lt;STRONG&gt;THANKS &lt;/STRONG&gt;&lt;SPAN&gt;I GET AN ANSWER BY RUNNING THE BELOW TEXT:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

fc = "D:\\Projects\\proj1\\SumsOfRoutes.gdb\\all_routes_1stBatch"
field1 = "r_Identity"
##field2 = "Shape_Length"

sql = [None,"Group BY r_Identity, ObjectID"]


fields=[field1]
cursor = arcpy.da.SearchCursor(fc,fields,sql_clause=sql)


# print r_Identity and Shape_Length of each feature in feature class
for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(row)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Only I don't understand the thing with the OBJECTID,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and more so, this constellation &lt;/SPAN&gt;&lt;STRONG&gt;DOES NOT HELP ME, AS I CAN'T REACH THE OTHER FIELDS OF THE FEATURES&lt;/STRONG&gt;&lt;SPAN&gt;. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;substitute field1 with "*" brings back the runtime error&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:17:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642204#M50057</guid>
      <dc:creator>yonatanrubinstein</dc:creator>
      <dc:date>2021-12-12T03:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642205#M50058</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;OK, &lt;STRONG&gt;THANKS &lt;/STRONG&gt;I GET AN ANSWER BY RUNNING THE BELOW TEXT:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

fc = "D:\\Projects\\proj1\\SumsOfRoutes.gdb\\all_routes_1stBatch"
field1 = "r_Identity"
##field2 = "Shape_Length"

sql = [None,"Group BY r_Identity, ObjectID"]


fields=[field1]
cursor = arcpy.da.SearchCursor(fc,fields,sql_clause=sql)


# print r_Identity and Shape_Length of each feature in feature class
for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(row)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Only I don't understand the thing with the OBJECTID,&lt;BR /&gt;&lt;BR /&gt;and more so, this constellation &lt;STRONG&gt;DOES NOT HELP ME, AS I CAN'T REACH THE OTHER FIELDS OF THE FEATURES&lt;/STRONG&gt;. &lt;BR /&gt;&lt;BR /&gt;substitute field1 with "*" brings back the runtime error&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You cannot use '*' when using sql_clause. You must specify each field explicitly.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:17:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642205#M50058</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-12T03:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642206#M50059</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is truly a strange and confusing method available for the da.SearchCursor.&amp;nbsp; I mean the GROUP BY clause is normally applied because you are attempting to summarize things (say SUM or AVERAGE, or other some such metric).&amp;nbsp; But it is entirely weird to require ObjectID which would negate any ability to correctly perform such aggragetion, let alone not even be able to include such a thing as COUNT, MIN, MAX, AVERGE, etc...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope I am simply missing the obvious here.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Apr 2014 14:50:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642206#M50059</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2014-04-08T14:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642207#M50060</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You cannot use '*' when using sql_clause. You must specify each field explicitly.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;OK, I GOT IT (I THINK). The same fields should be in the "group-by" part and in the "fields" part.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;THANK YOU JAMES, THANK YOU MATHEW&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it is very confusing, and the ObjectID part is weird, I wouldn't have got it on my own in a million years. Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Apr 2014 15:02:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642207#M50060</guid>
      <dc:creator>yonatanrubinstein</dc:creator>
      <dc:date>2014-04-08T15:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642208#M50061</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The OBJECTID should not be required, if it ever was it is a bug and is fixed in 10.2.1.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Apr 2014 15:53:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642208#M50061</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2014-04-08T15:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: using join by in arcpy.da.searchcursor() - what is the right syntax?</title>
      <link>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642209#M50062</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The OBJECTID should not be required, if it ever was it is a bug and is fixed in 10.2.1.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It is required/an issue at 10.1 SP1&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Apr 2014 16:21:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-join-by-in-arcpy-da-searchcursor-what-is-the/m-p/642209#M50062</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2014-04-08T16:21:09Z</dc:date>
    </item>
  </channel>
</rss>

