title: PostgreSQL SELECT latest date only for a combination of different columns
body: <p>I'm trying to query data in a way that gets all the instances of <code>id_description</code> but only the latest row based on the <code>date</code> column.</p>
  
  <p>My latest query attempt is...</p>
  
  <pre><code>SELECT DISTINCT ON (id) id, id_part, id_finish, id_metal, id_description, MAX(date) AS date, sort 
  FROM parts_finishing 
  WHERE id_description='3' 
  GROUP BY id 
  ORDER BY id DESC;
  </code></pre>
  
  <p>...which results in the following returned data...</p>
  
  <pre><code>+----+---------+-----------+----------+----------------+------------+------+
  | id | id_part | id_finish | id_metal | id_description | date       | sort |
  +----+---------+-----------+----------+----------------+------------+------+
  | 37 | 2997    | 1         | 12       | 3              | 2015-01-08 | 1    |
  +----+---------+-----------+----------+----------------+------------+------+
  | 36 | 2990    | 1         | 22       | 3              | 2015-01-07 | 2    |
  +----+---------+-----------+----------+----------------+------------+------+
  | 34 | 2990    | 1         | 22       | 3              | 2013-01-07 | 1    |
  +----+---------+-----------+----------+----------------+------------+------+
  </code></pre>
  
  <p>I need all the rows <code>WHERE id_description='3'</code> though only return one record for the part (a combination of the <code>id_part</code>, <code>id_finish</code> and <code>id_metal</code> columns). The row with <code>id</code> 34 I <em>don't</em> want returned in this example because it's <code>date</code> for the combined part number is older than <code>id</code> 36.</p>
  
  <p>On the client side their part number may look like '2990-01-22' so I need <em>only</em> the latest record for those three columns combined as a single effective column based on the latest <code>date</code>. So I need the query to return the rows of <code>id</code> 36 and 37. If it helps the inherent <code>date</code> (<code>date</code> type) and <code>id</code> (<code>serial</code> obviously) rows only ever increase, so there is no chance that the <code>date</code> rows will ever change from their initial value.</p>
  
  <p>So visually based off of the table above I need the query to return the following...</p>
  
  <pre><code>+----+---------+-----------+----------+----------------+------------+------+
  | id | id_part | id_finish | id_metal | id_description | date       | sort |
  +----+---------+-----------+----------+----------------+------------+------+
  | 37 | 2997    | 1         | 12       | 3              | 2015-01-08 | 1    |
  +----+---------+-----------+----------+----------------+------------+------+
  | 36 | 2990    | 1         | 22       | 3              | 2015-01-07 | 2    |
  +----+---------+-----------+----------+----------------+------------+------+
  </code></pre>