title: Select latest measurement results
body: <p>I have a <a href="http://www.postgresql.org/" rel="nofollow"><code>PostgreSQL</code></a> database table containing measurement results. Every measurement has a time column the measurement has been performed on, a metrics column containing the results from that measurement and an identifier identifying the object being measured.</p>
  
  <p>Since the table contains multiple measurements for the same object, I want to only select the latest measurement of each object.</p>
  
  <p>My approach was to order by the identifier and mess time descending and finally to eliminate duplicates retaining only the first row for each identifier. I also only want the metrics column to be returned. How is it done?</p>
  
  <pre><code>SELECT DISTINCT ON(id) FROM measurements ORDER by id, messon DESC LIMIT 10;
  </code></pre>
  
  <p>Not only does this query take a while, the resulting rows are also only tilde (<code>~</code>) symbols:</p>
  
  <pre><code>(10 rows)
  
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  ~
  </code></pre>
  
  <p>I'm using <a href="http://www.ubuntu.com/" rel="nofollow"><code>Ubuntu</code></a>.</p>