title: How select greatest rows in each types
body: <p>I have a table with PK(&quot;object&quot;, &quot;type&quot;, &quot;mid&quot;) and this structure:</p>
  <pre><code>+-----+----------+-------+---------+-----+
  | type|  object  | value | preview | mid |
  +-----+----------+-------+---------+-----+
  | t1  | uid-0001 |   2   | p1      | 1   |
  | t1  | uid-0002 |   10  | p2      | 1   |
  | t2  | uid-0001 |   1   | p1      | 1   |
  | t2  | uid-0003 |   5   | p3      | 1   |
  | t3  | uid-0005 |   10  | p5      | 2   |
  | t3  | uid-0001 |   40  | p1      | 2   |
  | t4  | uid-0004 |   5   | p4      | 2   |
  +-----+----------+-------+---------+-----+
  </code></pre>
  <p>The result I would like to achieve is:</p>
  <pre><code>+-----+----------+-------+---------+-----+
  | type|  object  | value | preview | mid |
  +-----+----------+-------+---------+-----+
  | t1  | uid-0002 |   10  | p2      | 1   |
  | t2  | uid-0003 |   5   | p3      | 1   |
  | t3  | uid-0001 |   40  | p1      | 2   |
  | t4  | uid-0004 |   5   | p4      | 2   |
  +-----+----------+-------+---------+-----+
  </code></pre>
  <p>The SQL I have tried is:</p>
  <pre><code>SELECT * 
  FROM table 
  WHERE value in (SELECT max(value) FROM table GROUP BY type) 
  GROUP BY type
  </code></pre>
  <p>But this fails because it gets an incorrect value when it`s more than one identical value in table.</p>
  <p>I have also tried</p>
  <pre><code>SELECT * 
  FROM (SELECT * FROM table ORDER BY value desc) x 
  GROUP BY type;
  </code></pre>
  <p>but it has same error.</p>
  <p>Example of incorrect results:</p>
  <pre><code>+-----+----------+-------+---------+-----+
  | type|  object  | value | preview | mid |
  +-----+----------+-------+---------+-----+
  | t1  | uid-0002 |   10  | p2      | 1   |
  | t2  | uid-0003 |   5   | p3      | 1   |
  | t3  | uid-0005 |   10  | p5      | 2   |
  | t4  | uid-0004 |   5   | p4      | 2   |
  +-----+----------+-------+---------+-----+
  </code></pre>
  <p>In this case rows for <code>t3</code> and <code>t1</code> used same value (10, that must be for t1) and selected it in both types (t1, t3);</p>