Add Join (Data Management)

Summary

Joins a layer to another layer or table (where 'layer' is a feature layer, table view, or raster layer with a raster attribute table) based on a common field.

The records in the Join Table are matched to the records in the input Layer Name. A match is made when the input join field and output join field values are equal. This join is temporary.

Illustration

Add Join

Usage

Syntax

AddJoin_management (in_layer_or_view, in_field, join_table, join_field, {join_type})
ParameterExplanationData Type
in_layer_or_view

The layer or table view to which the join table will be joined.

Mosaic Layer; Raster Catalog Layer; Raster Layer; Table View
in_field

The field in the input layer or table view on which the join will be based.

Field
join_table

The table or table view to be joined to the input layer or table view.

Mosaic Layer; Raster Catalog Layer; Raster Layer; Table View
join_field

The field in the join table that contains the values on which the join will be based.

Field
join_type
(Optional)

Specifies what will be done with records in the input that match a record in the join table.

  • KEEP_ALLAll records in the input layer or table view will be included in the output; also known as an outer join. This is the default.
  • KEEP_COMMONOnly those records in the input that match to a row in the join table will be present in the result; also known as an inner join.
Boolean

Code Sample

AddJoin Example (Python Window)

The following Python window script demonstrates how to use the AddJoin function in immediate mode.

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.MakeFeatureLayer_management ( "Habitat_Analysis.gdb/vegtype", "veg_layer")
arcpy.AddJoin_management( "veg_layer", "HOLLAND95", "vegtable.dbf", "HOLLAND95")
arcpy.CopyFeatures_management( "veg_layer", "Habitat_Analysis.gdb/vegjoin")
AddJoin Example 2 (stand-alone script)

This stand-alone script shows the AddJoin function as part of a workflow to join a table to a feature class and then extract desired features.

# Name: AttributeSelection.py
# Purpose: Join a table to a featureclass and select the desired attributes
# Author: ESRI

# Import system modules
import arcpy
from arcpy import env


try:
    # Set environment settings
    env.workspace = "C:/data"
    env.qualifiedFieldNames = False
    
    # Set local variables    
    inFeatures = "Habitat_Analysis.gdb/vegtype"
    layerName = "veg_layer"
    joinTable = "vegtable.dbf"
    joinField = "HOLLAND95"
    expression = "vegtable.HABITAT = 1"
    outFeature = "Habitat_Analysis.gdb/vegjoin"
    
    # Create a feature layer from the vegtype featureclass
    arcpy.MakeFeatureLayer_management (inFeatures,  layerName)
    
    # Join the feature layer to a table
    arcpy.AddJoin_management(layerName, joinField, joinTable, joinField)
    
    # Select desired features from veg_layer
    arcpy.SelectLayerByAttribute_management(layerName, "NEW_SELECTION", expression)
    
    # Copy the layer to a new permanent feature class
    arcpy.CopyFeatures_management(layerName, outFeature)
    
except Exception, e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message

Environments

Related Topics

Licensing Information

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes

10/27/2014