Batch Join Field

2582
4
Jump to solution
01-05-2021 08:31 AM
jblng
by
New Contributor III

Hello,

I am writing a for loop to iterate through the join field tool on a geodatabase of tables. My final goal is to have one table containing the fields of all other tables in the GDB. Here is the relevant code:

 

arcpy.env.workspace = r"C:\My_GDB.gdb"
join_field = "CommuneCode"
join_table = r"C:\My_GDB.gdb\chirps_2020_04_tbl"
tables = arcpy.ListTables()
counter = 1
for table in tables:
    print ("processing: " + table)
    arcpy.JoinField_management(table, join_field, join_table, join_field)
    print("%s of %s tables processed" % (counter, len(tables)))
    counter += 1

print("Processing complete.")

 

The actual results of this loop appends the fields from the join_table object onto each of the tables in the GDB. What I would actually like is the opposite, joining all tables in the GDB to the join_table. 

 

I would greatly appreciate any tips here. Thanks in advance! 

 

0 Kudos
1 Solution

Accepted Solutions
JoeBorgione
MVP Emeritus

Don't you want to  add a join?  

That should just about do it....

View solution in original post

4 Replies
DanPatterson
MVP Esteemed Contributor

Join Field (Data Management)—ArcGIS Pro | Documentation

did you try switch their order around?


... sort of retired...
jblng
by
New Contributor III

Hi @DanPatterson  thank you! I had also tried reversing the order but was still getting the same result. The suggestion from Joe Borgione to run Add Join worked for my use case.

0 Kudos
JoeBorgione
MVP Emeritus

Don't you want to  add a join?  

That should just about do it....
jblng
by
New Contributor III

Hi @JoeBorgione , thanks for the suggestion - this is what I needed. Sometimes the simpler option is the best one!

0 Kudos