title: ActiveRecord - How to use JOINS, GROUP and SELECT only certain columns?
body: <p>If I run following query,</p>
  
  <pre><code>  @top_companies               = Shipment.joins(:company)
                                          .where('...')
                                          .group('companie.name')
                                          .order('count_all DESC').limit(10).count
  </code></pre>
  
  <p>the output is in the <strong>company name => count of shipments</strong> format:</p>
  
  <pre><code>"Company name"=&gt;12, ...}
  </code></pre>
  
  <p>But I would need to fetch also other columns from the <code>companies</code> table, like the <code>id</code> and so on, so I tried:</p>
  
  <pre><code>  @top_companies               = Shipment.joins(:company)
                                          .select('shipments.*, companies.id, companies.name, companies.name_slug')
                                          .where('...')
                                          .group('companie.name')
                                          .order('count_all DESC').limit(10).count
  </code></pre>
  
  <p>But the output remains the same - why is that? How to add another columns to the output hash?</p>