title: Only insert into table if item does not exist
body: <p>My database has a table called <code>fruit</code>:</p>
  
  <h1>Table <code>fruit</code></h1>
  
  <pre><code>+-------------+
  | id | name   |
  + ----------- +
  | 1  | apple  |
  | 2  | orange |
  | 3  | banana |
  | 4  | grape  |
  +-------------+
  </code></pre>
  
  <p><code>id</code> is the a primary key. I want to add entries to the table, but only if they don't exist already.</p>
  
  <h1>The query</h1>
  
  <pre><code>IF NOT EXISTS (SELECT name FROM fruit WHERE name = 'mango')
  INSERT INTO fruit (name) 
  VALUES ('mango')
  </code></pre>
  
  <h1>Error</h1>
  
  <p>I use a SQL GUI app called <strong>Sequel Pro</strong>, and this query errors with the following:</p>
  
  <p><code>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 NOT EXISTS (SELECT name FROM fruit WHERE name = 'mango') INSERT INTO frui' at line 1</code></p>
  
  <h1>Perhaps</h1>
  
  <p>Something fishy may be going on. The query may be stopping at <code>INSERT INTO frui</code>. Problem with the app? Or is my query wrong?</p>