Join multiple tables to multiple feature classes arcpy

3092
12
Jump to solution
03-31-2020 10:39 AM
NataliaGutierrez1
New Contributor III

Hello,

I need help to create a script that would allow me to loop through multiple tables in a geodatabase and join them to the correct feature class in another geodatabase. There are in total 77 tables and 77 feature classes. I would tell GIS to join those where a portion of the table name matches a portion of the Feature class name. 

For example:

      Table Name 1: "NAL11F201901"

      Feature class 1: "T11"

       Table Name 2: "NAL12F201901

       Feature Class 2: "T12"

Important:

  • All of the tables and the feature classes have the same unique field name. 
  • I need to join all of the fields. 
  • The join needs to be permanent.

I am not sure if Add join is better to use or if I should use Join field.

I don't really know what to do next.

I would really appreciate any help with this. 

Thanks!

import arcpy

in_features = r"D:\APRX_MXDS\USA_Parcels_2019_Project\Florida_Parcels_Per_County_Final.gdb"
join_tables = r"D:\APRX_MXDS\USA_Parcels_2019_Project\Florida_Property_Data_Per_County.gdb"

list_infeatures = arcpy.ListFeatureClasses()
list_join_tables = arcpy.ListTables(*NAL)
UniqueField = "CO_PARCELID"

for fc in list_infeatures:
    arcpy.AddJoin_management()
0 Kudos
12 Replies
NataliaGutierrez1
New Contributor III

Joe, the code worked!!  I am so happy! thank you so much! I was really stuck and needed to do this automatically. I used to do all of this manually for such a long time and I am learning to automate this with your help and with as many videos I can find online. 

Actually, do you know of a good course that would teach me python applied to arcgis ? All I find are separate videos each one teaching different things. I would love to find something that goes from the very beginning until more advanced processes. 

Anyways.. thank you again!

0 Kudos
JoeBorgione
MVP Emeritus

I'm glad it worked.  There is an instructor lead esri course; I took it it some time back. It was okay.  I've mostly just picked it up on my own with a lot of help from this forum.  Using ArcGIS Pro you can run a tool, get the syntax figured out and then create a stand alone script based on that.  

There are lots of on-line python tutorials.  I like the w3schools stuff as they spell things out pretty succinctly. Python documentation is all over the web, so if just preface a question with 'python' you can usually find what you are looking for like 'python return last 7 letters in a string' or 'python for loop' or 'python if else'.....

That should just about do it....
0 Kudos
NataliaGutierrez1
New Contributor III

Thank you again! Will keep on learning and using the online tools 

0 Kudos