Scene:
There are two of the following tables
TableA
| Id |
ROW1 |
ROW2 |
ROW3 |
ROW4 |
| 1 |
2 |
3 |
4 |
5 |
TableB
At the beginning of the table B only ID, rowa_id two fields, for some convenience reasons, and so on, now to add a field "Rowa_row4", now to the previous records to supplement the corresponding ROWA_ROW4 data;
Analysis:
My first thought was to write a piece of Java code that loops out the data from the TableA and deposits it into the tableb;
Later Raigo gave a simple SQL solution, as follows.
SQL code
--Set not auto commit
SET AUTOTATBT = 0;
--Update data
UPDATE TableB TB
SET TB. Rowa_row4= (
SELECT ROW4 from TableA ta WHERE ta.id= TB. ROWA_ID);
--whether the query achieves the effect
SELECT * from TableA TA, TableB TB where ta.id= TB. rowa_id;
This article is from the "Ydhome" blog, make sure to keep this source http://ydhome.blog.51cto.com/8948432/1875992
MySQL Update old data