title: SQL Select only rows with Max Value on a Column revisited
body: <p><strong>Same old question:</strong> </p>
  
  <p>I have a table. I want the rows with max value for a field, grouped by a set of fields. BUT I do not need JUST the max value and group by fields, I need the full row (all other fields, so I can't just do:</p>
  
  <pre><code>select max(field1),  field2 from table group by field2; 
  </code></pre>
  
  <p>As I said, I need field3, field4, ... , fieldn. </p>
  
  <p>This has been treated before, and I found an excelent answer here:</p>
  
  <p><a href="https://stackoverflow.com/questions/7745609/sql-select-only-rows-with-max-value-on-a-column">SQL Select only rows with Max Value on a Column</a></p>
  
  <p>Basically, it says I should do a join between the original table, getting all fields from there, and a subquery that gets me the max and group by fields. And for most cases, that probably works.</p>
  
  <p><strong>My issue</strong></p>
  
  <p>For my particular case I am not so sure that approach works, because of the data types involved. Let me give an example.</p>
  
  <p>Consider this gives me the max values I want, grouped by the field I want:</p>
  
  <pre><code>select max(field1) maxf1, field2 f2 from mytable group by f2
  </code></pre>
  
  <p>The above link would suggest trying something like:</p>
  
  <pre><code>SELECT mt.field1, mt.field2, mt.field3, ... , mt.fieldn
  FROM mytable mt
  INNER JOIN (
      SELECT max(field1) maxf1, field2 f2 FROM mytable GROUP BY f2
  ) sq
  ON sq.maxf1 = mt.field1 AND sq.f2 = mt.field2
  </code></pre>
  
  <p>For my particular case, field1 and field2 may be of type FLOAT and TIMESTAMP. Therefore, the join comparisons <code>sq.maxf1 = mt.field1</code> and <code>sq.f2 = mt.field2</code> might not be the way to go (see <a href="https://stackoverflow.com/questions/17333/most-effective-way-for-float-and-double-comparison">What is the most effective way for float and double comparison?</a>). So, any hints for me on this one?</p>