0

I am trying to use upsert to update and or insert from another table

INSERT INTO table1 (
  `uniqueCol1`, 
  `uniqueCol2`, 
  `created`, 
  `dataCol`
) 
VALUES (
   1, 
   t1.uniqueCol2Value, 
   NOW(), 
   t1.dataColValue 
) 
ON DUPLICATE KEY UPDATE
   `dataCol` = t1.dataColValue

Now from what I can tell I don't see how I can add what I think should be FROM table2 t1 into this to grab the values and put them into table1

Nexus9988
  • 79
  • 1
  • 11

1 Answers1

1

I would suggest:

INSERT INTO table1 (
  `uniqueCol1`, 
  `uniqueCol2`, 
  `created`, 
  `dataCol`
) 
SELECT 1, uniqueCol2Value, NOW(), dataColValue FROM table2
Michel
  • 571
  • 1
  • 4
  • 19