title: if exists update else insert mysql
body: <pre><code>IF EXISTS (SELECT * FROM two_player  WHERE title='math' and user2 is null)
   UPDATE two_player  SET score2='50' , user2='zahra' WHERE title='math' and user2 is null
   ELSE  
   INSERT INTO two_player  (user1,score1,title) values ('zahra', '50', 'math')
  </code></pre>
  
  <p>This query works right in sql server. But I am getting this error in the mysql:</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 two_player WHERE title='math' and user2 is null) ' at line 1</p>
  </blockquote>
  
  <p>why?!
  what is the alternative for that?</p>