Ok, the title may be difficult to understand, but this is what I want to do.
I have a Table ‘A’ with a few columns.
I have a Table ‘B’ with the exact same columns.
During my program flow, I insert a few rows from ‘A’ into ‘B’ (sort of a temp cache).
Column data in ‘A’ may change, but when someone clicks the ‘restore’ button, I wanna copy those rows from ‘B’ back into ‘A’ and overwrite those rows with the same id as the ones i want to copy from ‘B’.
E.g.
Table A:
1 : Hi |
2 : Friends |
3 : What's up
During the flow i backup id 1 and 2
Table B:
1 : Hi |
2 : Friends
Now I do some stuff and table A changes a bit
Table A (changed):
1 : Hi diddely doo |
2 : Amigo's |
3 : What's up
Now I realise my changes are wrong, and I want to put the records with id 1 and 2 back in their original state, from table ‘B’.
Is there a ‘simple’ sql to do that, without fetching those id’s 1 by 1 and update it 1 by 1?
Thanks in advance!
You can use JOIN in UPDATE statements:
Or with implicit join:
You can delete and reinsert, that way you don’t have to specify columns if both tables have the same table scheme: