AnsweredAssumed Answered

Why sql_clause is not respected in da.SearchCursor?

Question asked by adamczi on Nov 19, 2017
Latest reply on Nov 21, 2017 by adamczi

I have a shapefile where I have polylines and their fields are:

 

- length

- area into which they fall in

 

Now I need 3 longest lines from each area. I have 3 areas and 50 polylines, so I should get 3*3=9 records as a result. What I try to do is:

 

import arcpy

myFile = somePath
sql = ('TOP 3', 'ORDER BY "length" DESC GROUP BY "area_id" ')

cursor = arcpy.da.SearchCursor(myFile , "*", None, None, False, sql)

with cursor:
    for r in cursor:
        print r

 

I get all of 50 records here. The same happens when I set `sql` to just `('TOP 1', None) or anything else.

 

Is the syntax wrong here?

Outcomes