title: Rails: find_by_sql uses the wrong ID
body: <p>I am using the following Ruby code:</p>
  
  <pre><code>sql = "SELECT *  FROM
         conversations
         INNER JOIN member_users ON member_users.conversation_id = conversations.id
  
  
         WHERE conversations.id = #{conversation.id}
         AND member_users.user_id = #{user.id}"
  
      cs = Conversation.find_by_sql(sql)
  </code></pre>
  
  <p>The query returns a single row. But, find_by_sql is returning the Conversation with the ID of the member_user, not the ID of the Conversation. This is because there are two "id" columns in the result, and find_by_sql seems to be using the wrong one.</p>
  
  <p>Is there any way to prevent this without using SELECT conversations.* instead of SELECT *?</p>
  
  <p>Why does this happen - why doesn't Rails use the first ID column it comes across? Is it because the row is returned in a hash?</p>
  
  <p>More generally, in SQL - is there a way to differentiate between different columns with the same name? Or are these meant to be equivalent? I often get confused when doing joins which result in several "id" cols.</p>
  
  <p>Thanks,
  Louise</p>