title: Performance: Subquery or Joining
body: <p>I got a little question about performance of a subquery / joining another table</p>
  
  <pre><code>INSERT
  INTO Original.Person
    (
      PID, Name, Surname, SID
    )
    (
      SELECT ma.PID_new , TBL.Name , ma.Surname, TBL.SID 
      FROM Copy.Person TBL , original.MATabelle MA
      WHERE TBL.PID         = p_PID_old
        AND TBL.PID         = MA.PID_old
    );
  </code></pre>
  
  <p>This is my SQL, now this thing runs around 1 million times or more.
  My question is what would be faster?</p>
  
  <ul>
  <li>If I change <code>TBL.SID</code> to (<code>Select new from helptable where old = tbl.sid</code>)  </li>
  </ul>
  
  <p>OR </p>
  
  <ul>
  <li>If I add the 'HelpTable' to the <code>from</code> and do the joining in the <code>where</code>?</li>
  </ul>
  
  <p><strong>edit1</strong><br>
  Well, this script runs only as much as there r persons.</p>
  
  <p>My program has 2 modules one that populates <code>MaTabelle</code> and one that transfers data. This program does merge 2 databases together and coz of this, sometimes the same Key is used.<br>
  Now I'm working on a solution that no duplicate Keys exists.</p>
  
  <p>My solution is to make a 'HelpTable'. The owner of the key(<code>SID</code>) generates a new key and writes it into a 'HelpTable'. All other tables that use this key can read it from the 'HelpTable'.</p>
  
  <p><strong>edit2</strong><br>
  Just got something in my mind:<br>
  if a table as a Key that can be null(foreignkey that is not linked)
  then this won't work with the from or?</p>