I have 2 tables, Let's name them tb1 and tb2.
I want to add all items in tb1 that dose not exist in tb2 into new rows in tb2. At the same time I want to update existing data in tb2 with the data in tb1, I try to understand join, merge and so on but I could not understand how doing that in SQL.
For the question I will build this 2 tables and the result I try to achieve.
tb1:
| KEY | col one | col two
+------+------------+-----------
| 1 | data one | data one
| 2 | data two | change data
| 3 | data three | data three
tb2:
| KEY | col one | col two
+------+-----------+-----------
| 1 | data one | data one
| 2 | data two | old data
| 4 | data four | some data
tb2 after SQL :
We can see we add the key 3 and we change in key 2, col 2 data
| KEY | col one | col two
+------+------------+-----------
| 1 | data one | data one
| 2 | data two | change data
| 3 | data three | data three
| 4 | data four | some data