title: Only inserting row when record doesn't already exist
body: <p>The table is called <code>limits</code> and takes the following fields:</p>
  
  <pre><code>id    |    ip    |    limit
  </code></pre>
  
  <p>on every page load, I'm checking if the user has a record in this table (determined by <code>ip</code>) and if they don't, I insert a record. However if the record already exists, I don't want to do anything.</p>
  
  <p>I basically need a <code>INSERT IF NOT EXISTS</code> type query. I've already read <a href="http://bogdan.org.ua/2007/10/18/mysql-insert-if-not-exists-syntax.html" rel="nofollow">this</a> and the <code>INSERT IGNORE</code> example looks good but as far as I can tell it only works for primary keys. In my case the <code>id</code> field is the primary key and I want to check if the <code>ip</code> already exists.</p>
  
  <p>Here's some sort of pseudo SQL code:</p>
  
  <pre><code>INSERT INTO `limits` (ip, limit)
  VALUES ('127.0.0.1', 8)
  IF NOT EXISTS `limits`.`ip`
  </code></pre>
  
  <p>Thanks for any help!</p>
  
  <p>EDIT: tried this too</p>
  
  <pre><code>INSERT IGNORE INTO `limits`
  SET `ip` = ‘127.0.0.1′,
  `limit` = 8;
  </code></pre>