title: MySQL select DISTINCT by highest value
body: <p>I have a table full of magazines, and need to extract the latest unique issue of each magazine. </p>
  
  <p>Ive tried</p>
  
  <pre><code>    SELECT DISTINCT
      magazine
          FROM
      product p
          INNER JOIN
      (SELECT 
          title, MAX(onSale) AS Latest
      FROM
          product
      GROUP BY magazine) groupedp
  </code></pre>
  
  <p>Which returns the distinct magazines , but not the rest of the data I require. </p>
  
  <p>UPDATE:</p>
  
  <p>schema</p>
  
  <pre><code>-id----onsale----magazine
    1    1/12/12   Fishing Mag
    2    1/11/12   Fishing Mag
    3    12/03/11  Pencil Sharpening Monthly
    4    1/02/10   Pencil Sharpening Monthly
    5    16/04/09  Homes in the Sky
  </code></pre>
  
  <p>So the result I would like returned would be:</p>
  
  <pre><code> -id----onsale----magazine
     1    1/12/12   Fishing Mag         
     3    12/03/11  Pencil Sharpening Monthly         
     5    16/04/09  Homes in the Sky
  </code></pre>