title: MYSQL Syntax error for Insert / Update query linked to a secondary table
body: <p>I have a query which is suppose to either update or insert based upon whether the row exists.</p>
  
  <p>I then also connect it to a secondary table so i can link them on the correct id's but im getting a syntax error and am unsure how to fix it.</p>
  
  <p>This is my query:</p>
  
  <pre><code>INSERT INTO resources as r (r.quantity,r.tid)
    SELECT r.quantity+?,u.tid                                             
      FROM users u WHERE u.uid = ? 
  ON DUPLICATE KEY UPDATE
     r.quantity = r.quantity+?, r.tid = u.tid
  </code></pre>
  
  <p>The error is </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 r (r.quantity,r.tid) SELECT 
  r.quantity+'0',u.tid FR' at line 1
  </code></pre>
  
  <p>Any one able to explain the what I have misunderstood and how i fix it?</p>