title: SQL: Update table when the table copying from has duplicate entries
body: <p>I have a table which contains unique names, call it table1. I have another table which contains the same names but each name occurs several times, call it table2. Now, I want to copy data from table2 to table1 corresponding to the names. And if table2 has multiple records by the same name, I want the corresponding new records to be created in table1.  </p>
  
  <pre><code>TABLE1                    TABLE2
  NAME                       NAME
  A                           A
  B                           A
  C                           B
  D                           B
  </code></pre>