title: How to do CosmosDB JOIN to get an array of Column values
body: <p>I have following data in cosmosDb</p>
  <pre><code>[
   { 
     accountId : &quot;12453&quot;
     tag : &quot;abc&quot;
   },
   {
     accountId : &quot;12453&quot;
     tag : &quot;bcd&quot;
   },
   { 
     accountId : &quot;34567&quot;
     tag : &quot;qwe&quot;
   },
   {
     accountId : &quot;34567&quot;
     tag : &quot;xcx&quot;
   }
  ]
  </code></pre>
  <p>And desired output is something like this</p>
  <pre><code>[
   {
     accountId : &quot;123453&quot;
     tag : {
         &quot;abc&quot;,
         &quot;bcd&quot;
    },
    {
     accountId : &quot;34567&quot;
     tag : {
         &quot;qwe&quot;,
         &quot;xcx&quot;
     }
    ]
  </code></pre>
  <p>I tried Join, array and group by in multiple ways but didn't work.</p>
  <p>Below query gives similar output but rather than count I am looking for an array of tags</p>
  <pre><code>  select c.accountId, count(c.tag) from c where c.accountId = &quot;12453&quot; group BY c.accountId
  </code></pre>
  <p>Also tried below query</p>
  <pre><code> select c.accountId, ARRAY(select c.tag from c IN f where f.accountId = &quot;12453&quot;) as tags FROM f 
  </code></pre>
  <p>This doesn't return any tag values and I get below output but I need distinct accountId and when I try DISTINCT on accountId, it gives an error.</p>
  <pre><code>   [ 
       {
       accountId : &quot;12,
       tag : []
       }
       ........
     ]
  </code></pre>
  <p>Can someone please help with correct query syntax</p>