title: ActiveRecord: Select max of limit
body: <p>I'm trying to convert the following SQL query to ActiveRecord and it's melting my brain.</p>
  
  <pre><code>delete from table where id &lt;= (
  select max(id) from (
      select id from table order by id limit 0, 10));
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>What I'm trying to do is limit the number of rows in the table. So, I want to delete anything that is less than the most recent 10 entries.</p>
  
  <p>edit:
  Found a solution by combining several of the below answers.</p>
  
  <pre><code>Temperature.where('id &lt; ?', Temperature.order('id DESC').limit(10).pluck(:id).min).destroy_all
  </code></pre>
  
  <p>This leaves me with the latest 10 entries.</p>