title: Joining 5 tables - 1 master plus 4 with multiple rows to the master but master data is duplicated
body: <p>I am working in mysql with queries, but I am new to this. I am joining 5 tables where each table has an identifier and one table is the master. Each related table may have more than one associated record to the master table. I am attempting to join these tables but I can't seem to get rid of the duplicated data. </p>
  
  <p>I want all of the related records to be displayed, but I don't want the data in the master table to display for all results in the related tables. I have tried so many different methods but nothing has worked. Currently I have 4 queries that work for the separate tables, but I have not successfully joined them to have the results display the multiple records in the related table but just one record from the master table. </p>
  
  <p>Here are my individual queries that work:</p>
  
  <pre><code>SELECT 
      GovernmaxAdditionsExtract.AdditionDescr, 
      GovernmaxAdditionsExtract.BaseArea, 
      GovernmaxAdditionsExtract.Value
  FROM 
      GovernmaxExtract 
      INNER JOIN GovernmaxAdditionsExtract 
          ON GovernmaxExtract.mpropertyNumber = GovernmaxAdditionsExtract.PropertyNumber
  WHERE (((GovernmaxExtract.mpropertyNumber)="xxx-xxx-xx-xxx"));
  
  SELECT 
      GovernmaxExtract.mpropertyNumber, 
      GovernmaxDwellingExtract.CardNumber, 
      GovernmaxDwellingExtract.MainBuildingType, 
      GovernmaxDwellingExtract.BaseArea
  FROM 
      GovernmaxExtract INNER JOIN 
      GovernmaxDwellingExtract ON GovernmaxExtract.mpropertyNumber = GovernmaxDwellingExtract.PropertyNumber
  WHERE (((GovernmaxExtract.mpropertyNumber)="xxx-xxx-xx-xxx"));
  </code></pre>
  
  <p>Using these sub queries, I tried to put together 2 of the tables, but now I am getting all records back and it is not reading my input parameter:</p>
  
  <pre><code>SELECT GE.mpropertynumber
  FROM 
      GovernmaxExtract AS GE, 
      (SELECT 
           GovernmaxAdditionsExtract.AdditionDescr, 
           GovernmaxAdditionsExtract.BaseArea, 
           GovernmaxAdditionsExtract.Value
       FROM GovernmaxExtract INNER JOIN 
           GovernmaxAdditionsExtract ON 
           governmaxextract.mpropertyNumber = GovernmaxAdditionsExtract.PropertyNumber) AS AE
  WHERE GE.mpropertynumber = 'xxx-xxx-xx-xxx'
  </code></pre>
  
  <p>I tried nested queries, lots of different joins, and I am just not able to wrap my head around this. I am pretty sure I want to do a nested query since I want the main data from the <code>Governmax</code> table to display once with the main data and all records with all info for the associated tables. Maybe I am going about it all wrong. </p>
  
  <p>Our original code was:</p>
  
  <pre><code>SELECT 
      ge.*, 
      gde.*, 
      gfe.*, 
      gae.*, 
      goie.* 
  FROM governmaxextract AS ge 
      LEFT JOIN governmaxdwellingextract AS gde 
          ON ge.mpropertyNumber = gde.PropertyNumber 
      LEFT JOIN governmaxfeaturesextract AS gfe
          ON gde.PropertyNumber = gfe.PropertyNumber  
      LEFT JOIN governmaxadditionsextract AS gae
          ON gde.PropertyNumber = gae.PropertyNumber  
      RIGHT JOIN governmaxotherimprovementsextract AS goie 
          ON gde.PropertyNumber = goie.PropertyNumber
  WHERE ge.mpropertyNumber = '$codeword'   
  ORDER BY goie.CardNumber
  </code></pre>
  
  <p>But this gives multiple rows from the master table for each record in the associated tables. I thought about concatenate, but I need the data from the associated tables to be displayed individually. Not sure what to try next. Any help is much appreciated.</p>