title: BigQuery: Aggregate multiple fields into array
body: <p>I have some data where for each ID I want to aggregate two or more fields into an array, and I want them to match in terms of order.</p>
  
  <p>So for example if I have the following data:</p>
  
  <p><a href="https://i.stack.imgur.com/PpHll.png" rel="noreferrer"><img src="https://i.stack.imgur.com/PpHll.png" alt="enter image description here"></a></p>
  
  <p>I want to turn it into this:</p>
  
  <p><a href="https://i.stack.imgur.com/nHHVq.png" rel="noreferrer"><img src="https://i.stack.imgur.com/nHHVq.png" alt="enter image description here"></a></p>
  
  <p>Alternatively, something like this would also be fine:</p>
  
  <p><a href="https://i.stack.imgur.com/CdaIb.png" rel="noreferrer"><img src="https://i.stack.imgur.com/CdaIb.png" alt="enter image description here"></a></p>
  
  <p>So firstly, if I were to use a query like this, would it do what I want or does it not guarantee that the two fields pull through in the same order (i.e. that the corresponding values in Value_1 and Value_2 may not match)?</p>
  
  <pre><code>SELECT
    ID,
    ARRAY_AGG (
      Value_1
    ) AS Value_1,
    ARRAY_AGG (
      Value_2
    ) AS Value_2
  
  FROM
    table
  
  GROUP BY
    ID
  </code></pre>
  
  <p>If not, how can I go about doing this?</p>