title: SQL Joining tables to get other tables data
body: <p>Let's assume the following table:</p>
  
  <pre><code>-- Register
  regid       descr               mainid      subid
    1         Registration #1     1           1
    2         Registration #2     2           3
    3         Registration #3     1           4
    4         Registration #4     2           2
  
  -- MainCat
  mainid      descr
    1         MainCat.1
    2         MainCat.2
  
  -- SubCat
  subid       descr
    1         SubCat.1
    2         SubCat.2
    3         SubCat.3
    4         SubCat.4
  </code></pre>
  
  <p>Howto get a result like this:</p>
  
  <pre><code>- Description: -     - MainCat -    - SubCat -
   Registration #1      MainCat.1      SubCat.1
   Registration #2      MainCat.2      SubCat.3
   Registration #3      MainCat.1      SubCat.4
   Registration #4      MainCat.2      SubCat.2
  </code></pre>
  
  <p>I tried a <code>left join</code> like</p>
  
  <pre><code>SELECT 
      Register.*,
      MainCat.descr AS MainCat,
      SubCat.descr AS SubCat
  FROM
      Register
  LEFT JOIN 
      MainCat ON
      Register.mainid = MainCat.mainid
  LEFT JOIN
      SubCat ON
      Register.subid = SubCat.subid
  WHERE
      Register.descr LIKE 'Registration%'
  </code></pre>
  
  <p>But somehow, it returns multiple of the same Register-records, with the wrong MainCat-descriptions. I'm feeling really dumb now :P</p>
  
  <p><em>Note: All the id's and descriptions of the categories (main and sub) are 100% unique. Also this is a simplified database of the original, but it has the same purpose.</em></p>
  
  <p><strong>So my questions are:</strong></p>
  
  <ul>
  <li>Did i correctly wrote my SQL?</li>
  <li>If yes: What could be the problem of the strange (duplicate) results</li>
  <li>If no: What is the right way to achieve this</li>
  </ul>
  
  <p>P.S. <code>DISTINCT</code> does'nt work because its returning (wrong) different <code>MainCat.descr</code> and so there not 100% duplicates</p>