title: Sql insert if row does not exist
body: <p>I have 3 tables called <code>table1</code> <code>table2</code> and <code>table3</code>. the <code>table3</code> contains records that have <code>table1.id</code> and <code>table2.id</code> and some other columns as well. So I need to do the following. for each record in table 1 I need to see if in table3 there is a row containing that table1.id and any other table2.id if there is no such record I want to insert it.</p>
  
  <p>so here is the example.</p>
  
  <p>suppose table1</p>
  
  <pre><code>1 ... ... ...
  2 ... ... ...
  </code></pre>
  
  <p>table2</p>
  
  <pre><code>10 .. .. ..
  20 .. .. ..
  </code></pre>
  
  <p>table3</p>
  
  <pre><code>1 | 10 .. .. ..
  2 | 20 .. .. ..
  </code></pre>
  
  <p>I need to add </p>
  
  <p><code>1 20 .. .. ..</code> and 
  <code>2 10 .. .. ..</code> rows to the table3 because for <code>table1.id</code> 1 it did not have the row which had all <code>table2.id</code>s (in this case 20) and for <code>table1.id</code> 2 it also did not have the row which had all <code>table2.id</code>s (in this case 10) in it. any help would be appreciated </p>