title: Using SWITCH() to split data from a column into distinct columns, with associated data in reach row
body: <p>I'm not quite sure how to properly phrase the question, but I am basically trying to develop an SQL query that <code>SELECTs</code> information from this table:</p>
  
  <pre><code>-------------------
  | id | Val | Date |
  |----|-----|------|
  | 1  |  A  | 10/9 |
  | 1  |  B  | 3/14 |
  | 2  |  A  | 1/6  |
  | 3  |  A  | 4/4  |
  | 4  |  B  | 7/12 |
  | 5  |  A  | 8/6  |
  -------------------
  </code></pre>
  
  <p>And produces a table that looks like this:</p>
  
  <pre><code>------------------------------------------------
  | id | Val_1 | Val_1_Date | Val_2 | Val_2_Date |
  |----|-------|------------|-------|-------------
  | 1  |  A    |   10/9     |  B    |   3/14     |
  | 2  |  A    |   1/6      |       |            |
  | 3  |  A    |   4/4      |       |            |
  | 4  |       |            |  B    |   7/12     |
  | 5  |  A    |   8/6      |       |            |
  ------------------------------------------------
  </code></pre>
  
  <p>I have already begun and developed the query to pull out the values in the Val fields into distinct columns:</p>
  
  <pre><code>SELECT * FROM 
  (
    SELECT id, MAX(SWITCH( val='A', 'A')) as Val_1, 
               MAX(SWITCH( val='B', 'B')) as Val_2
    FROM table1 GROUP BY id
  )a
  WHERE Val_1 IS NULL OR Val_2 IS NULL;
  </code></pre>
  
  <p>How would I expand on this to pull out their associated dates?</p>
  
  <p>(I am using <code>SWITCH()</code> instead of <code>CASE WHEN</code> because I am using a driver similar to that of MS Access.)</p>
  
  <p>Thanks!</p>