title: UPDATE if exists else INSERT in SQL
body: <p>I'm trying to implement a SQL query to "UPDATE if exists else INSERT"</p>
  
  <p>My table(<code>Allowance</code>) is as below:</p>
  
  <pre><code>EmployeeID int(8) PK
  Year year(4) PK
  Month int(2) PK
  OverTime decimal(10,2)
  Medical decimal(10,2)
  Lunch decimal(10,2)
  Bonus decimal(10,2)
  Allowance decimal(10,2)
  </code></pre>
  
  <p>Below is the SQL query I tried:</p>
  
  <pre><code>IF EXISTS (SELECT * FROM Allowance WHERE EmployeeID =10000001 and Year = 2014 and Month = 4)
      UPDATE Allowance
      SET OverTime = 10.00, Medical = 10.00, Lunch = 10.45, Bonus =10.10, Allowance = 40.55
      WHERE EmployeeID =10000001 and Year = 2014 and Month = 4
  ELSE
      INSERT into Allowance values (10000001,2014,4,10.00,10.00,10.45,10.10,40.55)
  </code></pre>
  
  <p>I keep getting this error message:</p>
  
  <blockquote>
    <p>"#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 EXISTS (SELECT * FROM Allowance WHERE EmployeeID =10000001 and Year = 2014 an' at line 1 "</p>
  </blockquote>
  
  <p>Can somebody please help??</p>