title: Update if exists, otherwise insert (without unique keys)
body: <p>I have a table that is created like this:  </p>
  
  <pre><code> 'CREATE TABLE `boss_kills` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `characterid` int(11) DEFAULT NULL,
    `mobid` int(11) DEFAULT NULL,
    `amount` int(11) NOT NULL DEFAULT ''0'',
    PRIMARY KEY (`id`)
  ) ENGINE=MyISAM AUTO_INCREMENT=25 DEFAULT CHARSET=latin1'
  </code></pre>
  
  <p><strong>Goal</strong>: I'm trying to create a system where a player kills a boss in the game and it records the boss's ID and the player's ID in the table. I want to be able to write one query where it updates if the player is already logged with the specific boss and inserts if he or she isn't.  </p>
  
  <p><strong>Research</strong>: I did a lot of research online and people suggest the <code>INSERT INTO ... ON DUPLICATE KEY UPDATE</code>, but that only works if you either know your primary key or have a unique key, none of which I have or know. </p>
  
  <p><strong>Tries</strong>: I've tried </p>
  
  <pre><code>IF EXISTS (...) THEN UPDATE (...) ELSE INSERT(...) 
  </code></pre>
  
  <p>and </p>
  
  <pre><code>UPDATE (...) IF @@ROWCOUNT = 0 INSERT INTO (...)
  </code></pre>
  
  <p>but they don't work. I get syntax errors. </p>
  
  <p>If needed I can provide the errors thrown by the above tries. My current code for trying to update is this (but it throws a SQL syntax error):  </p>
  
  <p>Attempt 1:</p>
  
  <pre><code>UPDATE boss_kills 
    SET amount = amount + 1 
    WHERE characterid = ? AND mobid = ? 
  IF @@ROWCOUNT = 0 
    INSERT INTO boss_kills (characterid, mobid, amount) VALUES (?, ?, 1) 
  </code></pre>
  
  <p>Attempt 2:</p>
  
  <pre><code>IF NOT EXISTS (SELECT id FROM boss_kills WHERE characterid = ? AND mobid = ?) 
  THEN 
    INSERT INTO boss_kills VALUES (DEFAULT, ?, ?, 1) 
  ELSE 
    UPDATE boss_kills SET amount = amount + 1 WHERE characterid = ? AND mobid = ?
  </code></pre>