title: MySQL: Combine multiple rows (with null values) into one row?
body: <p>I have a table called code_status:</p>
  
  <pre><code>  Code     Message
      1     "Start"
      2     "In process"
      3     "Finish"
  </code></pre>
  
  <p>And another table called history</p>
  
  <pre><code> ID   Code    Name      time_date
   1     2      Jon       1/2/15
   31    1      Abby      2/1/15
   12    3      Sara      3/3/15
   31    2      Abby      2/3/15
   31    3      Abby      2/5/15
   8     2      Max       1/22/15
  </code></pre>
  
  <p>I want to create an history_view with the following schema: </p>
  
  <pre><code>history_view (id, name, start_date, process_date, finish_date)
  </code></pre>
  
  <p>If the date is not given, it would just be NULL</p>
  
  <p>So it would look like</p>
  
  <pre><code>ID   Name    start_date    process_date      finish_date
  31   Abby     2/1/15          2/3/15           2/5/15
  1    Jon      NULL            1/2/15            NULL
  ... etc
  </code></pre>
  
  <p>So i started off by doing :</p>
  
  <pre><code>CREATE VIEW history_view
  AS SELECT h.id, h.name, 
  (CASE WHEN h.code = 1 THEN time_date) AS start_date,
  (CASE when h.code = 2 THEN time_date) AS process_date,
  (CASE when h.code = 3 THEN time_date) AS finish_date
  FROM history h;
  </code></pre>
  
  <p>I would get a result like the following below though:</p>
  
  <pre><code>ID   Name    start_date    process_date      finish_date
  31   Abby     2/1/15         NULL               NULL
  31   Abby      NULL          2/3/15             NULL
  31   Abby      NULL          NULL             2/5/15
  ... ETC
  </code></pre>
  
  <p>Is there any way to consolidate the rows together ?</p>