title: SQL Insert into table only if record doesn't exist
body: <p>I want to run a set of queries to insert some data into an SQL table but only if the record satisfying certain criteria are met. The table has 4 fields: <code>id</code> (primary), <code>fund_id</code>, <code>date</code> and <code>price</code></p>
  
  <p>I have 3 fields in the query: <code>fund_id</code>, <code>date</code> and <code>price</code>.</p>
  
  <p>So my query would go something like this:</p>
  
  <pre><code>INSERT INTO funds (fund_id, date, price)
      VALUES (23, '2013-02-12', 22.43)
      WHERE NOT EXISTS (
         SELECT * 
         FROM funds 
         WHERE fund_id = 23
           AND date = '2013-02-12'
      );
  </code></pre>
  
  <p>So I only want to insert the data if a record matching the <code>fund_id</code> and <code>date</code> does not already exist. If the above is correct it strikes me as quite an inefficient way of achieving this as an additional select statement must be run each time.</p>
  
  <p>Is there a better way of achieving the above?</p>
  
  <p>Edit: For clarification neither <code>fund_id</code> nor <code>date</code> are unique fields; records sharing the same fund_id or date will exist but no record should have both the same fund_id and date as another.</p>