0

Is there any way that I can use the output of subquery as the fields of the next query?

SELECT TEAM_ID, ID1, ID2, ID3 FROM XYZ;

to

SELECT TEAM_ID, (SELECT IDs FROM ABC WHERE GROUP_ID="1") FROM XYZ;

Schema for XYZ

TEAM_ID, ID1, ID2, ID3
   50, B001, A003, S001 
   60, B002, A111, M001 

Schema for ABC

Group_ID, IDs
1, ID1,ID2,ID3
2, ID1,ID3
3, ID2

Now, I want: TEAM_ID, ID1, ID2, ID3 50, B001, A003, S001

Based on Group_ID=1

AmirCS
  • 321
  • 1
  • 2
  • 14

1 Answers1

0

You can use join:

SELECT X.TEAM_ID, A.*
FROM X CROSS JOIN
     (SELECT IDs FROM ABC WHERE ABC.GROUP_ID = '1') a
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • Thanks Gordon! This returns back the field names, but it would not be able to query these fields and the content of the columns in BigQuery. I added an example to the question. Do you think this is something even possible? Thanks so much and sorry for the confusion! – AmirCS Sep 26 '19 at 15:45