title: PostgreSQL Select the r.* by MIN() with group-by on two columns
body: <h2>The example schema of a table called <code>results</code></h2>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>user_id</th>
  <th>activity_id</th>
  <th>activity_type_id</th>
  <th>start_date_local</th>
  <th>elapsed_time</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>100</td>
  <td>11111</td>
  <td>1</td>
  <td>2014-01-07 04:34:38</td>
  <td>4444</td>
  </tr>
  <tr>
  <td>2</td>
  <td>100</td>
  <td>22222</td>
  <td>1</td>
  <td>2015-04-14 06:44:42</td>
  <td>5555</td>
  </tr>
  <tr>
  <td>3</td>
  <td>100</td>
  <td>33333</td>
  <td>1</td>
  <td>2015-04-14 06:44:42</td>
  <td>7777</td>
  </tr>
  <tr>
  <td>4</td>
  <td>100</td>
  <td>44444</td>
  <td>2</td>
  <td>2014-01-07 04:34:38</td>
  <td>12345</td>
  </tr>
  <tr>
  <td>5</td>
  <td>200</td>
  <td>55555</td>
  <td>1</td>
  <td>2015-12-22 16:32:56</td>
  <td>5023</td>
  </tr>
  </tbody>
  </table>
  </div><h2>The problem</h2>
  <p>Select the results of fastest activities (i.e. minimum elapsed time) of each user by <code>activity_type_id</code> and <code>year</code>.</p>
  <p>(Basically, in this simplified example, record ID=3 should be excluded from the selection, because record ID=2 is the fastest for user 100 of the given activity_type_id 1 and the year of 2015)</p>
  <h2>What I have tried</h2>
  <pre><code>SELECT user_id,
         activity_type_id,
         EXTRACT(year FROM start_date_local) AS year,
         MIN(elapsed_time) AS fastest_time
  FROM results
  GROUP BY activity_type_id, user_id, year
  ORDER BY activity_type_id, user_id, year;
  </code></pre>
  <h3>Actual</h3>
  <p>Which selects the correct result set I want, but only contains the grouped by columns</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>user_id</th>
  <th>activity_type_id</th>
  <th>year</th>
  <th>fastest_time</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>100</td>
  <td>1</td>
  <td>2014</td>
  <td>4444</td>
  </tr>
  <tr>
  <td>100</td>
  <td>1</td>
  <td>2015</td>
  <td>5555</td>
  </tr>
  <tr>
  <td>100</td>
  <td>2</td>
  <td>2014</td>
  <td>12345</td>
  </tr>
  <tr>
  <td>200</td>
  <td>1</td>
  <td>2015</td>
  <td>5023</td>
  </tr>
  </tbody>
  </table>
  </div><h3>Goal</h3>
  <p>To have the actual full record with all columns. i.e. <code>results.*</code> + <code>year</code></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>user_id</th>
  <th>activity_id</th>
  <th>activity_type_id</th>
  <th>start_date_local</th>
  <th>year</th>
  <th>elapsed_time</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>100</td>
  <td>11111</td>
  <td>1</td>
  <td>2014-01-07 04:34:38</td>
  <td>2014</td>
  <td>2014</td>
  </tr>
  <tr>
  <td>2</td>
  <td>100</td>
  <td>22222</td>
  <td>1</td>
  <td>2015-04-14 06:44:42</td>
  <td>2015</td>
  <td>5555</td>
  </tr>
  <tr>
  <td>4</td>
  <td>100</td>
  <td>44444</td>
  <td>2</td>
  <td>2014-01-07 04:34:38</td>
  <td>2014</td>
  <td>12345</td>
  </tr>
  <tr>
  <td>5</td>
  <td>200</td>
  <td>55555</td>
  <td>1</td>
  <td>2015-12-22 16:32:56</td>
  <td>2015</td>
  <td>5023</td>
  </tr>
  </tbody>
  </table>
  </div>