title: Duplicate records using inner join with Three tables
body: <p>I am currently working with 3 tables and I am finding difficulty in constructing a SQL query which returns unique set of records. I am using Oracle SQL.</p>
  
  <p>If I include the UDG_Description fields I get duplicate records.</p>
  
  <p>I have tried using 'distinct' on the Table1.MachId but I think that is incorrect way of using it for my query. </p>
  
  <p>I noticed that if I include the UDG_Description I get duplicates but I need the description of the record from Table 3 in regards to the output i am trying to generate.</p>
  
  <p>I appreciate if someone can assist me please?</p>
  
  <p>Below is the current setup i am currently working with</p>
  
  <p><strong>Table1</strong></p>
  
  <ul>
  <li>MachId</li>
  <li>MachCode</li>
  <li>MachLinkType</li>
  </ul>
  
  <p><strong>Table2</strong></p>
  
  <ul>
  <li>LevId</li>
  <li>Lev_UDG_Code(linked to the Table 3)</li>
  <li>Lev_MachCode(linked to table1)</li>
  </ul>
  
  <p><strong>Table3</strong></p>
  
  <ul>
  <li>UDG_Id</li>
  <li>UDG_prefix</li>
  <li>UDG_code</li>
  <li>UDG_description</li>
  </ul>
  
  <p><strong>Note</strong>
  The UDG_CODE is not unique. The udg_prefix and udg_id have to be unique.</p>
  
  <pre><code>SELECT distinct(MachId), MachCode, MachLinkType, Lev_UDG_Code, UDG_Description 
  from Table1 INNER JOIN Table2
  ON Table1.MachCode = Table2.Lev_MachCode
  INNER JOIN Table2 ON
  Table3.UDG_Code = Table2.Lev_UDG_Code
  WHERE MachLinkType = 'ATX' AND Lev_UDG_Code = '12A89'
  </code></pre>
  
  <p>Kind Regards,</p>