title: SQL select distinct only highest values
body: <p>Lets say we have such table:</p>
  
  <p><img src="https://i.stack.imgur.com/cJYjs.png" alt="table"></p>
  
  <p>i only what to select unique plans with highest time, and also being able to select other columns. To ilustrate here's a query(witch obviously wouldn't work):</p>
  
  <pre><code>SELECT DISTINCT(plan), time, id
  FROM table
  ORDER BY time desc
  </code></pre>
  
  <p>how can i get such table:</p>
  
  <pre><code>plan|time|id
  ----+----+--------
  1   |0   |9
  2   |90  |10
  3   |180 |11
  4   |360 |12
  5   |720 |13
  6   |1080|15
  7   |0   |16
  8   |720 |23
  </code></pre>