title: SQL: Group rows by field a or field b
body: <p>I am not sure this is possible in SQL. I have two fields "a" and "b" in my table. I want to group records in the table when rows have the same "a" values or the same "b" values and then extract a value of another field with the latest timestamp. Would this be possible? I am using Redshift.</p>
  
  <p>Here is an example table:</p>
  
  <pre><code>|| key1 || key2 || date || value ||
  | 1 | 'a' | '2019-01-01' | 'john' |
  | 1 | 'b' | '2019-01-03' | 'ben' |
  | 2 | 'c' | '2019-02-01' | 'kim' |
  | 3 | 'c' | '2019-02-02' | 'dan' |
  | 4 | 'd' | '2019-02-03' | 'jan' |
  </code></pre>
  
  <p>Eventually what I want to have is:</p>
  
  <pre><code>| 'ben' |
  | 'dan' | 
  | 'jan' |
  </code></pre>