title: mySQL largest value by unique entry
body: <p>I have tried to solve the following problem for the last couple of hours and could not find anything that pointed me in the right direction on Google or Stackoverflow. I believe that <a href="https://stackoverflow.com/questions/28026906/mysql-largest-number-by-group">this</a> could be a similar problem, but I did not really understand what the author wanted to achieve, hence I am trying it with my own concrete example:</p>
  
  <p>I have a table that basically tracks prices of different products over time:</p>
  
  <pre><code>+------------+--------+----------+
  | Product_id | Price  |   Time   |
  +------------+--------+----------+
  |          1 |  1.30  | 13:00:00 |
  |          1 |  1.10  | 13:30:00 |
  |          1 |  1.50  | 14:00:00 |
  |          1 |  1.60  | 14:30:00 |
  |          2 |  2.10  | 13:00:00 |
  |          2 |  2.50  | 13:30:00 |
  |          2 |  1.90  | 14:00:00 |
  |          2 |  2.00  | 14:30:00 |
  |          3 |  1.45  | 13:00:00 |
  |          3 |  1.15  | 13:30:00 |
  |          3 |  1.50  | 14:00:00 |
  |          3 |  1.55  | 14:30:00 |
  +------------+--------+----------+
  </code></pre>
  
  <p>I would now like to query the table so that the rows with max. Price for each product are returned:</p>
  
  <pre><code>+------------+--------+----------+
  | Product_id | Price  |   Time   |
  +------------+--------+----------+
  |          1 |  1.60  | 14:30:00 |
  |          2 |  2.50  | 13:30:00 |
  |          3 |  1.55  | 14:30:00 |
  +------------+--------+----------+
  </code></pre>
  
  <p>Also, in case of duplicates, i.e. if there is a max. Price at two different points in time, it should only return one row, preferably the one with the smallest value of time.</p>
  
  <p>I have tried MAX() and GREATEST(), but could not achieve the desired outcome to show the wanted values for each product. Efficiency of the query is not the most important factor, but I have about 500 different products with several million rows of data, hence splitting the table by unique product did not seem like an appropriate solution.</p>