I have several tables where there are approximately 10 common columns, but some tables have 1-2 extra columns.
I would like to combine all these tables into one table with a row for each row from each table, with NULL values ββfor any columns that did not exist in each particular source row table.
So my inputs look something like this:
table1 id | colA | colB table2 id | colA | colB | colC table3 id | colA | colB | colD
And I'm trying to do this:
allTables id | colA | colB | colC | colD
In the above example, all rows from table1 will have NULL values ββfor colC and colD in all tables, all rows from table2 will have zero values ββfor colD, and all rows from table 3 will have zero values ββin colC.
A few notes:
- The column identifier does not match or is not related between tables.
- My example shows 3 tables, but I have about 8-9.
- Duplicate rows exist in each source table and must be preserved.
In particular, I am interested in whether there is an answer similar to the top one voted here or something like this, which is more general.
source share