Search code examples
sqldatabasegoogle-cloud-platformgoogle-bigqueryetl

Query to put two rows together on Google Big Query?


I have two tables with similar structures on Google Big Query:

TABLE 1

dt_sell cod_material cod_channel
2022-01-01 12 vd
2022-01-02 14 vd

TABLE 1

dt_sell cod_material cod_channel
2022-01-01 12 ecm
2022-01-01 13 ecm

I need to put the rows of one table under the other one, like this:

dt_sell cod_material cod_channel
2022-01-01 12 vd
2022-01-02 14 vd
2022-01-01 12 ecm
2022-01-01 13 ecm

How could I do this by running a query on Big Query? I can't create a new table for it, it needs to be on a query.


Solution

  • Consider using UNION

    SELECT dt_sell, cod_material, cod_channel FROM table_one
    UNION 
    SELECT dt_sell, cod_material, cod_channel FROM table_two