title: Rails manipulate sql data to return unique column values
body: <p>I have a RoR app that does a join between multiple tables and returns the resultset as json back to the client.
  I need help in figuring out how to send unique column values only.
  For e.g., if you have an employee and department table, doing a join on the two would return:</p>
  
  <pre><code>Physics   John   
  Physics   Joe
  Math      Charlie
  Math      Sheila
  </code></pre>
  
  <p>How can I return data back to the client that removes duplicate values, for e.g.</p>
  
  <pre><code>Physics =&gt; { John, Joe }
  Math = &gt; { charlie, Sheila }
  </code></pre>
  
  <p>I want to reduce unnecessary sending of duplicate data over the wire. </p>
  
  <p>Any thoughts?</p>
  
  <p>EDIT:</p>
  
  <p>Changed it to this (found it on stack overflow) and it worked:</p>
  
  <pre><code>@lec_hash = @lectures.inject({}) do | result, row |
      result[row.subject] = [] if result[row.subject].nil?
      result[row.subject] &lt;&lt; row.name
      result
  end
  </code></pre>