title: IF row exists THEN delete row in mysql
body: <p>I have a query like this:</p>
  
  <pre><code>IF EXISTS(SELECT 1 FROM table1 WHERE col1 = ? LIMIT 1) THEN
  DELETE FROM table2 WHERE col2 = ?
  END IF
  </code></pre>
  
  <p>But I don't know why above query does not work. Also this does not work too:</p>
  
  <pre><code>IF  EXISTS(SELECT 1 FROM table1 WHERE col1 = ? LIMIT 1) BEGIN
  DELETE FROM table2 WHERE col2 = ?
  END
  </code></pre>
  
  <p>MySQL tell my there is a syntax error, How can I fix it?</p>