title: How do you do a Rails 3 select IN using where clauses
body: <p>I am using Rails 3 and I need to do a select where the primary key of the records is IN a resulting previous select.  You can do this easily using straight SQL using an IN.  Here is the obviously incorrect way I have done what I need.  What's the Rails way to do this well:</p>
  
  <pre><code>@task = Link.find(params[:id])
  clients = Client.where('task_id = ?',@task.id).select('DISTINCT(company_id)')
  company_list = []
  clients.each do |client|
    company_ids &lt;&lt; client.company_id
  end
  @companies = Company.where(:id =&gt; company_ids)
  </code></pre>