How can I select every other record in a very large attribute table other than interactively?

2721
6
11-03-2017 08:42 AM
CherieMoritz2
New Contributor II

I am using ArcMap 10.5.1.  My table contains pairs of parcel numbers and looks like this.  Thank you.

0 Kudos
6 Replies
XanderBakker
Esri Esteemed Contributor

It seems like the table is sorted on PARCEL_NO. Would it be possible to sort this table and create a new table, or is that not an option. This would probably create new OBJECTID and that would allow you to select by attributes using the following SQL:

MOD (OBJECTID, 2) = 0

 

CherieMoritz2
New Contributor II

The table order is important in this case.  Cherie

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Given a parcel number, which address to you want to select?  The low or high address, e.g., 1066 Pine St or 1068 Pine St?

0 Kudos
CherieMoritz2
New Contributor II

Either all the high addresses or all low addresses.  It doesn't matter which, as long as it's consistently high or low.  Cherie

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

You can generate an OID list and then pass every other element to Layer.setSelectionSet:

lyr = # ArcPy mapping layer object
fields = ["OID@", "PARCEL_NO", "WHOLEADDRESS"]
sql = "ORDER BY PARCEL_NO, WHOLEADDRESS"

with arcpy.da.SearchCursor(lyr, fields, sql_clause=(None,sql)) as cur:
    oid_list = [row[0] for row in cur]

lyr.setSelectionSet("NEW", oid_list[::2])


    
CherieMoritz2
New Contributor II

That's great!  Thanks for your help.  I will give it a try.  Cherie

0 Kudos