title: Delete all rows that don't contain the max value in group
body: <p>I have a twist to this popular question and accepted answer:  <a href="https://stackoverflow.com/questions/612231/how-can-i-select-rows-with-maxcolumn-value-distinct-by-another-column-in-sql">How can I SELECT rows with MAX(Column value), DISTINCT by another column in SQL?</a></p>
  
  <p>I have a table structured similarly but instead of SELECTing the rows with the highest datatime I'd like to DELETE all the rows within each ID grouping that don't contain the max datetime.  The query should make the table smaller in terms of rows.</p>
  
  <p>I've tried using the accepted answer's select query in a WHERE NOT EXISTS sub query but I get the error  "You can't specify target table ... for update in From clause"</p>
  
  <p>How would you alter this to DELETE the rows that don't meet the SELECT requirement here:</p>
  
  <pre><code>SELECT tt.*
  FROM topten tt
  INNER JOIN
      (
       SELECT home, MAX(datetime) AS MaxDateTime
       FROM topten
       GROUP BY home
      ) groupedtt ON tt.home = groupedtt.home AND tt.datetime = groupedtt.MaxDateTime
  </code></pre>