title: mysql - Connecting three tables and combining different items in one cell
body: <p>I have this three different tables:</p>
  
  <p><code>business</code> contains information about different companies.</p>
  
  <pre><code>business
  -------------------------------------------------
    id     registry   city_id   primary_activity_id
  -------------------------------------------------
    12     24212432         1                     1
   123     43143321         2                     3     
   432     53242123         3                   431
  </code></pre>
  
  <p><code>business_activity</code> describes the secondary activities of each company.</p>
  
  <pre><code>business_activity
  ------------------------------------------------
  business_secondary_activities_id     activity_id
  ------------------------------------------------
                                12             765
                               123             109
                               432               8
                                12             431
                                12               1
                               432               3
  </code></pre>
  
  <p><code>activity</code></p>
  
  <pre><code>activity
  -----------------------------------
    id     identifier     description
  -----------------------------------
     1           24-2    construction
     3           35-1     consultancy
   431           12-3   manufacturing
   765           23-2     electronics
   109           34-2        software 
     8            1-2          retail
  </code></pre>
  
  <p>They are connected in the following way:</p>
  
  <ul>
  <li><p>business.id = business_activity.business_secondary_activities_id</p></li>
  <li><p>business.primary_activity_id = activity.id</p></li>
  <li><p>business_activity.activity_id = activity.id</p></li>
  </ul>
  
  <p>I want to build only one table that looks like this:</p>
  
  <pre><code>business
  ----------------------------------------------------------------------------------------------------------------------------------------
    id     registry   city_id   primary_activity_id  primary_activity_identifier secondary_activities_ids  secondary_activities_identifier
  ----------------------------------------------------------------------------------------------------------------------------------------
    12     24212432         1                     1                        24-2                765,431,1                  23-2, 12-3, 24-2
   123     43143321         2                     3                        35-5                      109                              34-2
   432     53242123         3                   431                        12-3                      8,3                         1-2, 35-1
  ----------------------------------------------------------------------------------------------------------------------------------------
  </code></pre>
  
  <p>Note that the <code>secondary_activities_id</code>'s and <code>secondary_activity_identifier</code>'s are combined in one cell and separated by commas.</p>
  
  <p>Could someone help?</p>