title: MySQL DELETE FROM with subquery as condition
body: <p>I am trying to do a query like this:</p>
  
  <pre><code>DELETE FROM term_hierarchy AS th
  WHERE th.parent = 1015 AND th.tid IN (
      SELECT DISTINCT(th1.tid)
      FROM term_hierarchy AS th1
      INNER JOIN term_hierarchy AS th2 ON (th1.tid = th2.tid AND th2.parent != 1015)
      WHERE th1.parent = 1015
  );
  </code></pre>
  
  <p>As you can probably tell, I want to delete the parent relation to 1015 if the same tid has other parents. However, that yields me a syntax error:</p>
  
  <pre><code>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS th
  WHERE th.parent = 1015 AND th.tid IN (
    SELECT DISTINCT(th1.tid)
    FROM ter' at line 1
  </code></pre>
  
  <p>I have checked the documentation, and run the subquery by itself, and it all seems to check out. Can anyone figure out what's wrong here?</p>
  
  <p><strong>Update</strong>: As answered below, MySQL does not allow the table you're deleting from be used in a subquery for the condition.</p>