title: MySQL INSERT Using Subquery with COUNT() on the Same Table
body: <p>I'm having trouble getting an <code>INSERT</code> query to execute properly, and I can't seem to find anything on Google or Stack Overflow that solves this particular issue.</p>
  
  <p>I'm trying to create a simple table for featured entries, where the <code>entry_id</code> is saved to the table along with it's current order.</p>
  
  <p>My desired output is this:</p>
  
  <p>If the <code>featured</code> table currently has these three entries:</p>
  
  <pre><code>featured_id    entry_id    featured_order
  1              27          0
  2              54          1
  4              23          2
  </code></pre>
  
  <p>I want the next entry to save with <code>featured_order</code>=3.</p>
  
  <p>I'm trying to get the following query to work with no luck:</p>
  
  <pre><code>INSERT INTO `featured`
  (
      `entry_id`, `featured_order`
  )
  VALUES
  (
      200,
      (SELECT COUNT(*) AS `the_count` FROM `featured`)
  )
  </code></pre>
  
  <p>The error I'm getting is: <code>You can't specify target table 'featured' for update in FROM clause</code>.</p>
  
  <p>Can anyone help with a solution that gets the count without causing an error?</p>
  
  <p>Thanks in advance!</p>