title: Join on multiple ids
body: <p>I've been helping a friend out with some of his MySQL queries, and came up with this query. While writing this I kind of wondered if there wasn't a better way to do this:</p>
  
  <pre><code>select offers.*, users.*, items.* from offers 
  join users on users.id = offers.sender_id
  join items on 
      (items.id = offers.receiver_gets_1)
  or
      (items.id = offers.receiver_gets_2)
  or
      (items.id = offers.receiver_gets_3)
  or
      (items.id = offers.receiver_gets_4)
  or
      (items.id = offers.sender_gets_1)
  or
      (items.id = offers.sender_gets_2)
  or
      (items.id = offers.sender_gets_3)
  or
      (items.id = offers.sender_gets_4)
  where receiver_id = 1;
  </code></pre>
  
  <p>It kind of made me feel bad, because I really have the feeling I gave him some messed up query (not that he minds). It has left me wondering if there isn't a nicer way to write this down?</p>
  
  <p>I tried looking on google for stuff like these questions:<br>
  - <a href="https://stackoverflow.com/questions/20472046/mysql-left-join-on-multiple-conditions">Mysql Left Join on multiple conditions</a><br>
  - <a href="https://stackoverflow.com/questions/498197/mysql-how-to-join-tables-on-two-fields">MySQL how to join tables on two fields</a><br>
  - <a href="https://dba.stackexchange.com/questions/33996/which-is-better-many-join-conditions-or-many-where-conditions">https://dba.stackexchange.com/questions/33996/which-is-better-many-join-conditions-or-many-where-conditions</a>  </p>
  
  <p>But these didn't really offer any other way. I did run in to another question where the answer was set-up the same as my own query.</p>
  
  <p>I know the database could perhaps modeled better, but it's not my database to toy with. I don't really agree with how his tables are built up or anything, but the question remains interesting to me non the less.</p>