INSERT INTO `tableA`
SELECT `Col1`,
`Col2`,
NOW()
FROM `tableB`
WHERE tableA.Col1 is not already in tableB.Col1
I can't get the WHERE clause right to ensure that the record copied from tableA only appears in table B once...
should read:
where tableA.col1 not in (select col1 from table B)
You really want the SQL-2003 MERGE statement. I've included the BNF for the MERGE statement (section 14.9, p837) from the standard (grotesque, but that's the SQL standard for you) below. When translated, that might translate to:
I have not run that past an SQL DBMS that knows about the MERGE statement - that means there are probably bugs in it. Note that there is a WHEN MATCHED clause which can take an UPDATE in the standard; IBM DB2 also supports a DELETE clause which is not in the 2003 standard (not sure about the 2008 standard).
14.9
<merge statement>
(p837)You can use the INSERT ... ON DUPLICATE KEY UPDATE syntax.