Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to dynamically join tables in bigquery to avoid duplication of common columns

I have 2 tables with a large number of columns (each has around 700-800 columns, which makes it not feasible to individually write all the column names). Both the tables have a few common rows. I need to dynamically union both the tables such that the common columns don’t get repeated and are queried only once in the final table. For example:

TABLE 1:
+---------+--------+------+-------+
|firstname|lastname|upload|product|
+---------+--------+------+-------+
|    alice|       a|   100|apple  | 
|      bob|       b|    23|orange |
+---------+--------+------+-------+

TABLE 2:

+---------+--------+------+-------+
|firstname|lastname|books |active |
+---------+--------+------+-------+
|    alice|       a|   10 |yes    | 
|      bob|       b|    2 |no     |
+---------+--------+------+-------+

FINAL TABLE:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

+---------+--------+------+-------+-----+------+
|firstname|lastname|upload|product|books|active|
+---------+--------+------+-------+-----+------+
|    alice|       a|   100|apple  | 10  | yes  |
|      bob|       b|    23|orange | 2   | no   | 
+---------+--------+------+-------+-----+------+

>Solution :

Just to give you a direction to look into

select *
from table1
join table2
using(firstname, lastname)          

if applied to sample data in your question – output is

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading