title: sql if exists update else insert not working
body: <p>i have a table with 3 generic keys which are also foreign keys. This is my query --</p>
  
  <pre><code>        IF (EXISTS(SELECT * FROM table1 WHERE col_1 =4))
          BEGIN 
          UPDATE table1 
      SET col_2 = 3,
      col_3 = 100
          WHERE col_1 = 4 
          END
          ELSE 
          BEGIN
          INSERT INTO table1 
      (col_1, col_2, col_3) 
          VALUES(4, 2, 27)
          END
  </code></pre>
  
  <p>This gives me a syntax error. Engine used InnoDB. Collation: utf8_swedish_ci</p>
  
  <p>I tried this too --</p>
  
  <pre><code>              INSERT INTO table1
      (col1, col2, col3)
       VALUES
      (:val1, :val2, :val3)
      ON DUPLICATE KEY UPDATE
      col2=:val2,
      col3=:val3
  </code></pre>
  
  <p>This doesn't work properly and only insert the rows inspite of having duplicate keys.</p>