0

Aim: In Python, I would like to populate a table "Units_temp" with records, then join "Units_temp" with table "Units" and update "Units". In other words, all items in "Units_temp" which does not exist in "Units" yet should be added to "Units". When the joining is done I would like to empty "Units_temp" so it is clean when i put new records into it the next time. I am using MS Access pyodbc.

inserting records into "Units_temp" works, it is the joining part I am struggling with.

enter image description here

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
NewDev
  • 71
  • 1
  • 7
  • What you've described is commonly known as an "upsert". There is an example for SQL Server [here](https://stackoverflow.com/a/62388768/2144390) that uses UPDATE and INSERT. A solution for Access would be very similar. – Gord Thompson Oct 05 '20 at 15:25
  • 1
    See the second answer on the duplicate, you can just use an `UPDATE` with a `LEFT JOIN`, a bit more simple than what's required in SQL server. The fact that pyodbc and Python are used should not be relevant – Erik A Oct 05 '20 at 15:48
  • See also https://github.com/gordthompson/sqlalchemy-access/wiki/%5Bfaq%5D-upsert-from-DataFrame-to-existing-table – Gord Thompson Oct 18 '20 at 22:39

0 Answers0