BigQuery Standard SQL - querying 3 different tables with same schema. How to add column with what table each row is from?

Viewed 132

Say I have 3 tables containing clothing brands from - walmart, target, amazon. I make a new table and query * from each table into this new table. I want to know which company (walmart, target or amazon) each of these items is from. How would I go about doing this in BigQuery?

Thank you.

1 Answers

Use below approach

select *, 'table1' as source from table1 union all
select *, 'table2' from table2 union all
select *, 'table3' from table3
Related