I have two tables as below.
Tabel A:
ResultID(PK) | ImportDate | Comment1
-------------------------------------
101 | 25-09-2019 | One
--------------------------------------
102 | 25-09-2019 | Two
--------------------------------------
103 | 25-09-2019 | Three
----------------------------------------
Table B:
ResultID(PK) | ImportDate | Comment2
-------------------------------------
101 | 26-09-2019 | new one
--------------------------------------
104 | 26-09-2019 | four
--------------------------------------
So the output should look like
Table A:
ResultID(PK) | ImportDate | Comment1
-------------------------------------
101 | 26-09-2019 | new one
--------------------------------------
102 | 25-09-2019 | Two
--------------------------------------
103 | 25-09-2019 | Three
--------------------------------------
104 | 26-09-2019 | four
--------------------------------------
Question:
I want to get resulting Table A as mentioned above if ResultID
is matched between Table A and Table B, I want to update all column in Table A from Table B for that ResultID
. If ResultID
from Table B is not present in Table A, insert it to Table A.
What I have tried in MySQL:
UPDATE TableA
SET comment1=
(SELECT comment2 FROM TableB WHERE TableA.ResultId=TableB.ResultId);
Above solution only works for one column to update Table A. I also tried with multiple column update reference from SQL Server 2005 implementation of MySQL REPLACE INTO? but multiple column update is not working for my scenarios.
For my real scenarios- I have 40 columns and 50,000 rows.
Could you please provide me any hint or solution? Thank you.