title: Selecting max value for a column in Oracle
body: <p>I have a table which has data like this  </p>
  
  <pre><code>id    test_val    type_cd  
  #-------------------------  
  101   TEST22      M  
  102   TEST23      M  
  103   TEST01      M  
  103   TEST01      H  
  104   TEST02      M  
  104   TEST02      H  
  105   TEST03      H  
  </code></pre>
  
  <p>I would like to fetch the max(id) for each type_cd and its corresponding test_val in a single row output as below.  </p>
  
  <p>The expected output is:  </p>
  
  <pre><code>M_id  M_Test_Val   H_id   H_Test_Val  
  #-----------------------------------
  104   TEST02       105    TEST03  
  </code></pre>
  
  <p>If I have to fetch only the max(id) for each type_cd I'll have my query like this  </p>
  
  <pre><code>select max(case when type_cd='M' then max(id) else null end) as M_id,
         max(case when type_cd='H' then max(id) else null end) as H_id
  from t1
  group by type_cd;
  </code></pre>
  
  <p>I'm not sure how to get the test_val for the <code>max(id)</code> for each <code>type_cd</code>.</p>