Combine Tables to ONE TABLE

What I’m trying to do:

  • Combining 2 Tables in One New Table e.g. columns or complete table

What I’ve tried and what’s not working:

  • the code below is combining them, but the values from T2 are not in row line with T1
  • any solution?
  • is there a way to copy a complete column in another table or Links Between Tables for columns?

Code Sample:

import itertools
def bt_iteration():
    app_tables.lkt_3.delete_all_rows()
    table_t1 = app_tables.lkt_1.search()
    table_t2 = app_tables.lkt_2.search()

    combined_table = itertools.chain(table_t1, table_t2)
    for rows in combined_table:
      pass
      app_tables.lkt_3.add_row(**rows)

I don’t understand, .chain() takes two iterables and goes through one, and then the other?

I think you want something more like:

for lkt1_row, lkt2_row in zip(app_tables.lkt_1.search(), app_tables.lkt_2.search()) :
  app_tables.lkt_3.add_row(**lkt1_row, **lkt2_row )

This also assumed the natural order of each table is what you want to be combined, otherwise you need more parameters or sorting added to your table searches.
…It also assumes they are the same length, if they are not you have to specify that inside the zip() function.

Hi Ian,

exactly what I was looking for, appreciate the fast support :+1:!

1 Like