title: MySQL Join 3 cascading tables
body: <p>I have seen plenty of examples to join multiple tables back to one master table but this query is different in that it cascades.</p>
  
  <p>I have 3 tables similar to the below (simplified for ease):</p>
  
  <pre><code>**CONTACTS**     
  --------------------------------------------
  Cid    name
  --------------------------------------------
  1      John
  2      Peter
  3      Karl
  
  
  **OPPORTUNITIES**
  --------------------------------------------
  Oid   Cidlink   title
  --------------------------------------------
  1     2         php lookup script
  2     2         php facial recognition
  3     3         html email template
  4     1         javascript verification
  
  **ATTACHMENTS**
  --------------------------------------------
  Aid    Oidlink  attachment
  --------------------------------------------
  1     3         received enquiry
  2     3         header and footer done
  3     3         pixel trace image done on server
  4     2         database structure done      
  5     2         html get form done
  </code></pre>
  
  <p>As you can see, attachments link back to opportunities and opportunities relate to contacts.  Attachments do not link directly to contacts except via the opportunity table.</p>
  
  <p>I need to create a recordset including fields from all 3 tables and am struggling.</p>
  
  <pre><code>SELECT CONTACTS.*, OPPORTUNITIES.*, ATTACHMENTS.*
  FROM ATTACHMENTS
      INNER JOIN OPPORTUNITIES
          ON CONTACTS.Cid = OPPORTUNITIES.Cidlink
      INNER JOIN ATTACHMENTS
          ON OPPORTUNITIES.Oid = ATTACHMENTS.Oidlink
  
  ORDER BY ****whatever****
  </code></pre>
  
  <p>Am I close or am I approaching this the wrong way?</p>