tgroussell

How do I select unmatched records in joined featureclass?

Discussion created by tgroussell on Oct 5, 2012
I have two feature classes in a file geodatabase that I join together on a key field. I want to select records from the target feature class
that have no matching records in the joined feature class. What is the correct method of doing this? I can do this by selecting matches
and reversing the selection, but there must be a better way.


[HTML]    arcpy.management.MakeFeatureLayer(target_feature_class,"target_layer")

    arcpy.management.AddJoin("target_layer","BYST",join_feature_class,"BYST")


    # This returns all records:
    arcpy.management.SelectLayerByAttribute("target_layer", "NEW_SELECTION", '"join_feature_class.BYST" is Null')

    # This returns all records:
    arcpy.management.SelectLayerByAttribute("target_layer", "NEW_SELECTION", '"target_layer.BYST" <> "join_feature_class.BYST"')

    # this returns the records with no match in the joined feature class
    arcpy.management.SelectLayerByAttribute("target_layer", "NEW_SELECTION", '"target_layer.BYST" = "join_feature_class.BYST"')
    arcpy.management.SelectLayerByAttribute("target_layer", "SWITCH_SELECTION")[/HTML]

Outcomes