Ilja
Ilja

Reputation: 1053

BigQuery - seeing results of multiple queries horizontally next to each other

I'm building a report and exporting it to GSheets. However, instead of running 4 to six calls to BQ (different projects), I'd like to make one call and extract the result as something like

T1.field1 | T1.field2 | T2.field3 | T2.field4 | etc.

The point is that these output data are not related to each other and the sizes of the output tables are different as well. I thought to have null in the shorter tables.

The only solution I could think of is to add another column with row number and make a full join on the row number.

If you have better solution, I'd love to hear. Thanks!

Upvotes: 0

Views: 682

Answers (1)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 173191

instead of joining you can consider union as it is in simplified example below. results are not horizontally layout - but still one call and friendly enough for spreadsheet to manipulate with

SELECT output, field1, field2, field3, field4, field5, field6
FROM 
  (SELECT 't1' AS output, field1, field2, field3
   FROM (SELECT 1 AS field1, 2 AS field2, 3 AS field3)),
  (SELECT 't2' AS output, field4, field5, 
   FROM (SELECT 4 AS field4, 5 AS field5)),
  (SELECT 't3' AS output, field6 
   FROM (SELECT 6 AS field6))  

Upvotes: 0

Related Questions