title: select distinct columns from db2 table
body: <p>I'm using spring batch to read from table and write the data to another table and I'm using spring writer for the insertion part. My problem is:</p>
  
  <p>I'm getting data from a table that looks like the following:</p>
  
  <pre><code>cust   type   date
  ====   =====  ====
   1       P    1985
   1       P    1980
   1       P    1970
   2       P    1984
  </code></pre>
  
  <p>and I'm trying to insert these data to another table by running a query that <code>select distinct( cust , type)</code> from the above table to get the following result:</p>
  
  <pre><code>cust   type   date
  ====   =====  ====
   1       P    1985
   2       P    1984 
  </code></pre>
  
  <p>so basically what I want to do is to get the distinct set of <code>cust and type</code> and if there are multiple records for this <code>cust. type</code> set then I get the <code>max(date)</code>.</p>
  
  <p>Is there anyway to do so in using query? or any recommendation for an efficient approach?</p>
  
  <p>Thanks in advance!</p>
  
  <blockquote>
    <p>UPDATE:</p>
  </blockquote>
  
  <p>there are some records in date that have NULL value so for example </p>
  
  <pre><code>cust   type   date
  ====   =====  ====
   1       P    NULL
   1       P    NULL
   1       P    NULL
   2       P    1984
  </code></pre>
  
  <p>and if I query for <code>max(date)</code> it will not return back any record from <code>cust(1)</code> .. any suggestions will be appreciated!</p>