title: How to merge several rows that share the same foreign key, into columns?
body: <p>I have a main table that stores information about the general details of a sample. There are also several rows in another table that have the main tables id as a foreign key. I want to merge the id's of these individual rows and the main table id into columns on a single row.</p>
  
  <p>I've tried writing a view that creates rows joining data between sample_admittance. The problem is that it would create several rows to fit a unit id in only one column for each join.</p>
  
  <pre class="lang-sql prettyprint-override"><code> SELECT
      mt.project,
      mt.project_name,
      mt.client,
      mt.date,
      mt.location,
      u.unit,
      u.status
     FROM main_table mt
       JOIN units u ON u.main_table_id::text = mt.id::text;
  </code></pre>
  
  <p>I wanted it organized like:</p>
  
  <pre><code>main_table_id | unit_1 | unit_2 | unit_3 | ... | unit_10
  </code></pre>
  
  <p>but instead get multiple rows</p>
  
  <pre><code>main_table_id | unit
  
  id_1          | un1
  id_1          | un3
  id_2          | un1
  </code></pre>