I'm making a Python script using ArcPy for ArcGIS Pro and I have joined a Feature Class and a Table View to create a new feature class. All of the fields and rows I need are present, however there are rows that contain duplicate values for the foreign key of the Table View.
I realize that the issue that I'm having is that I am performing a 1:M join when I really want something more along the lines of a 1:first matching record join. I believe using the Group By SQL clause would resolve this issue in a normal database situation, but I'm not sure how to duplicate this functionality in ArcPy.
This is the working code that I have so far:
table_view = arcpy.management.MakeTableView(joinFeatures, "tableview", joinExpr)
arcpy.CopyRows_management(table_view, "tableview_temp")
FL = arcpy.management.AddJoin(targetFeatures, "segmentid", "tableview_temp", "segmentidfkey", "KEEP_COMMON")
arcpy.CopyFeatures_management(FL, out_layer)
The targetFeatures feature class contains a single instance of each segmentid that I'm joining on, and the "tableview_temp" has multiple records containing the matching segmentidfkey.
I need the output feature class to only contain one record for segmentid even if multiple segmentidfkey matches.