Use SQL, returning JSON, to build Table 1 and Table 2:
Table 1 data will be something like:
[
{'id': 1, 'col1': 'AAA', 'col2':BBB},
{'id': 2, 'col1': 'FFF', 'col2':GGG}
]
Table 2 will be something like:
[
{'id': 1, 'col1': 111, 'col2': 222, 'StepName':1},
{'id': 1, 'col1': 444, 'col2': None, 'StepName':2},
{'id': 1, 'col1': None, 'col2': 888, 'StepName':3},
]
Then organize the data with a script like:
table_1 = [
{'id': 1, 'col1': 'AAA', 'col2':'BBB'},
{'id': 2, 'col1': 'FFF', 'col2':'GGG'}
]
table_2 = [
{'id': 1, 'col1': 111, 'col2': 222, 'StepName':1},
{'id': 1, 'col1': 444, 'col2': None, 'StepName':2},
{'id': 1, 'col1': None, 'col2': 888, 'StepName':3},
]
result_value = []
for item in table_1:
if item['id'] == 1:
col_dict = item
del col_dict['id']
break
for item in table_2:
if item['id'] == 1:
result_value.append({col_dict_val: item[col_dict_key] for col_dict_key, col_dict_val in col_dict.items()})
result_value[-1]['StepName'] = item['StepName']
print result_value