title: Update Database if data exists else Insert in MySQL in a single step
body: <p>For my Application, I need to check whether data exists for some column. If exists, add a value 10 to the existing value else insert a new entry</p>
  
  <p>I'm trying something like this</p>
  
  <pre><code>UPDATE reporting set column_name1 = column_name1 + 10 WHERE column_name2 = "201";
  IF ROW_COUNT()=0 THEN
      INSERT INTO reporting (column_name1,column_name2) VALUES (15,201);
  END IF
  </code></pre>
  
  <p>In my Table column_name2 is not a primary Key and I have disabled Safe checks.Due to this reason, I cannot use DUPLICATE KEY constraint.For this Query, I'm getting Syntax Error: </p>
  
  <p><code>Error Code: 1064. 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 'IF @@ROWCOUNT=0 THEN     INSERT INTO reporting (identifier,_9_2017) ' at line 1</code></p>
  
  <p>The syntax of If statement is similar to the one in MySQL Documentation <a href="https://dev.mysql.com/doc/refman/5.7/en/if.html" rel="nofollow noreferrer">https://dev.mysql.com/doc/refman/5.7/en/if.html</a>. There are few Questions related to this in this portal but I couldn't find the right answer (<a href="https://stackoverflow.com/questions/30569666/update-if-exists-else-insert-in-sql">UPDATE if exists else INSERT in SQL</a>). Where am I going wrong here? </p>