title: SQL: Insert into Ignore if Exist
body: <p>I want to <code>insert from Table1 the rows are not in Table2.</code> </p>
  
  <p>The thing is a mistake to have the Node with <code>parentId = 0</code> on the Table2. </p>
  
  <p>So I need to get all the sons from all parent are in Table2 and <code>insert</code> them if they are not on Table2 with the Key the parent used to have on Table2.</p>
  
  <p>I have for each table two keys, not just one. There is my problem. </p>
  
  <p>Plz if someone can give me hand. I could use <code>cursors</code>.</p>
  
  <pre><code>Table1
  IDNode, IDParent
  1       0
  2       1
  3       1
  4       1
  5       0
  6       5
  
  
  Table2
  IDNode, IDKey
  1       1
  1       7
  2       6
  4       2
  5       3
  
  
  
  
  
  IdNode  IDparent IDkey
  2       1           1
  3       1           1
  4       1           1
  2       1           7
  3       1           7
  4       1           7
  remove the IDNode2 with IDKey6
  remove the IDNode4 with IDKey2
  6       5           4
  </code></pre>
  
  <p>The key of the father is more important, if in my Table2 I have a parent with a key, I need to find form table1 the sons, insert them with the key of father, if exist the son with different key delete it, after all delete  the parent node from table2</p>