title: Selecting name from aggregated ID in Postgresql
body: <p>I have no clue how to do this.</p>
  <pre><code>    (Select Dane1.Name, Array_agg(Dane1.UpperCat) as &quot;upper_category&quot;, count(Dane1.UpperCat) As data_count, dane1.room_id
          From
              (Select 
                      contact.room_id,
                      UpperCategory_Id As &quot;UpperCat&quot;, /* uppper category ID of rooms */
                      Rooms.Name As &quot;Name&quot;,
                      Rooms.Type
                  From Public.contact
                  Join Rooms On contact.room_id= Rooms.Rooms_Id) As Dane1
      Group by Dane1.Name, Dane1.UpperCat,dane1.room_id) 
  </code></pre>
  <p><strong>Result:</strong></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Name</th>
  <th>upper_category</th>
  <th>data_count</th>
  <th>room_id</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Room 1</td>
  <td>{25,25,25,25}</td>
  <td>4</td>
  <td>150</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>The goal is to count how many times the upper category occurs AND what's the name of said category.</p>
  <p>It's all in Rooms table but I can't get that, only sub room ID's name. I don't care about {25,25,25,25} but the name that corresponds to that ID in the aggregate function.</p>