title: How to set correct limit for mysql delete statement
body: <p>I have a script that checks for duplicate pairs in a database and selects all entries that need to be deleted except for one.</p>
  
  <p>I have this script that selects the first 100 entries that need to be deleted and works fine:</p>
  
  <pre><code>SELECT*  
    FROM vl_posts_testing 
    INNER JOIN (
         SELECT max(ID) AS lastId, `post_content`,`post_title`
         FROM vl_posts_testing WHERE vl_posts_testing.post_type='post'
         GROUP BY `post_content`,`post_title`
         HAVING count(*) &gt; 1) duplic 
    ON duplic.`post_content` = vl_posts_testing.`post_content` 
    AND duplic.`post_title` = vl_posts_testing.`post_title`
  WHERE vl_posts_testing.id &lt; duplic.lastId 
  AND vl_posts_testing.post_type='post' 
  LIMIT 0,100
  </code></pre>
  
  <p>However when I try to delete this set of data using:</p>
  
  <pre><code>DELETE vl_posts_testing 
    FROM vl_posts_testing 
    INNER JOIN (
         SELECT max(ID) AS lastId, `post_content`,`post_title`
         FROM vl_posts_testing WHERE vl_posts_testing.post_type='post'
         GROUP BY `post_content`,`post_title`
         HAVING count(*) &gt; 1) duplic 
       ON duplic.`post_content` = vl_posts_testing.`post_content` 
       AND duplic.`post_title` = vl_posts_testing.`post_title`
  WHERE vl_posts_testing.id &lt; duplic.lastId 
  AND vl_posts_testing.post_type='post' 
  LIMIT 100
  </code></pre>
  
  <p>I receive the fallowing error: </p>
  
  <blockquote>
    <p>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 'LIMIT 10' at line 8</p>
  </blockquote>
  
  <p>The script has been constructed using this answer <a href="https://stackoverflow.com/a/6108860/1168944">https://stackoverflow.com/a/6108860/1168944</a></p>
  
  <p>Actually the script works just fine on a small amount of data without the limits set, however due to the fact that I run it on a big table (some 600k entries) I need to split this script in a routine that processes only a limited amount of data due to server limits like processor, memory etc.</p>
  
  <p>Also took into consideration this example: <a href="https://stackoverflow.com/questions/6111961/mysql-limit-on-delete-statement">MySQL LIMIT on DELETE statement</a> but the result is different since no modification is executed no matter how small is the limit.</p>