Reputation: 87
In my database I have two tables. In table A, I use Update to makes increment exp: update number set lastnumber = lastnumber + 1 once got new rerods entered.
How to assign the value from table A to table B?
Upvotes: 1
Views: 771
Reputation: 14361
Join two tables to update, assuming you have a relationship between the two tables... Since you table A is already updated by SET A.lastnumber = A.lastnumber + 1
, you may use A.lastnumber
(the new value) to update B.lastnumber
UPDATE B
SET B.lastnumber = A.lastnumber
FROM TABLE B
JOIN TABLE A
ON A.ID = B.ID
;
You may also add where
clause if you have other more distinct columns and conditions to validate for the join and update...
Upvotes: 1