Select to view content in your preferred language

One to Many Relate - Make Query Table

3522
2
Jump to solution
04-11-2013 12:11 PM
by Anonymous User
Not applicable
Original User: SStrand

I just cannot wrap my head around using the Make Query Table help section work with a python script to relate a set of points to multiple table records.

I have a set of points with an ID field and a table with the same ID field occurring multiple times with different values for each. I need a list of those values. Could anyone help with this?

Thanks
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
Original User: JSkinn3

Hi Steve,

I don't believe the Make Query Table will not show a 1-Many relationship.  What you could do is iterate through your first table and append the IDs to a list.  Then, iterate through the list and find all related records to the ID and print out the corresponding attributes.  Ex:

import arcpy from arcpy import env env.workspace = r"C:\temp\python\test.gdb"  table1 = "Gages" table2 = "Mains"  table1List = []  #append IDs to list rows = arcpy.SearchCursor(table1) for row in rows:     table1List.append(row.getValue("ID"))  del row, rows  table2List = []  #iterate through list and find related records for n in table1List:     rows = arcpy.SearchCursor(table2)     for row in rows:         if n == row.ID:             #append related records to a new list             table2List.append(row.X)             table2List.append(row.Y)     print str(n) + "\n\t" + str(table2List)     #clear list for next ID     table2List = []  del row, rows

View solution in original post

0 Kudos
2 Replies
by Anonymous User
Not applicable
Original User: JSkinn3

Hi Steve,

I don't believe the Make Query Table will not show a 1-Many relationship.  What you could do is iterate through your first table and append the IDs to a list.  Then, iterate through the list and find all related records to the ID and print out the corresponding attributes.  Ex:

import arcpy from arcpy import env env.workspace = r"C:\temp\python\test.gdb"  table1 = "Gages" table2 = "Mains"  table1List = []  #append IDs to list rows = arcpy.SearchCursor(table1) for row in rows:     table1List.append(row.getValue("ID"))  del row, rows  table2List = []  #iterate through list and find related records for n in table1List:     rows = arcpy.SearchCursor(table2)     for row in rows:         if n == row.ID:             #append related records to a new list             table2List.append(row.X)             table2List.append(row.Y)     print str(n) + "\n\t" + str(table2List)     #clear list for next ID     table2List = []  del row, rows
0 Kudos
by Anonymous User
Not applicable
Original User: SStrand

Hi JSkinn,

Thanks for the suggestion to work around this, I will give it a try!
0 Kudos