I have multiple tables in the following format:
table users -
ID lang
1 EN
2 EN
3 DE
table A -
ID event1 event2
1 5 1
2 null 1
3 11 null
table B -
ID event1 event10
1 2 1
3 2 null
so after concat/join the tables on ID column my final table would look like this:
final_table -
ID lang A_event1 A_event2 B_event1 B_event10
1 EN 5 1 2 1
2 EN null 1 null null
3 DE 11 null 2 null
So I have multiple issues here, first how to properly do the joins so that aliases would match table names and have final unique column names even though the events have same naming inside the columns, and also I would like all the missing values would also have null values (like table B that does not have user ID = 2).
My tries so far were not successful as the column names would be duplicated without unique IDs and missing values were not filled with nulls properly.
example for what I already tried:
select t1.*, t2.*, t3.*
from users t1
left join
A t2
using (ID)
left join
B t3
using (ID)
I can construct the query programmatically to provide flexability, but I would like to know the proper syntax for such case.
Thanks.