mysql table update from other table -
i have 2 tables.
table1
a - b - c- d - e 1---b1---c1---d1---e1 2---b2---c2---d2---e2 3---b3---c3---d3---e3 4---b4---c4---d4---e4 5---b5---c5---d5---e5 table2
a----b----c----d----e 1---b2---c2---d2---e2 3---b3---c3---d3---e3 5---b5---c5---d5---e5 6---b6---c6---d6---e6 some information on table1 not included in table2 - need update table 2 copy of table2. tried
update table1 t1, table2 t2 set t2.b = t1.b, t2.c = t1.c, t2.d = t1.d but 0 rows affected - not change have made. can else?
first: need insert records not presented in table2 table1:
insert table2(a, b, c, d, e) select t1.* table1 t1 left join table2 t2 on t1.a = t2.a t2.a null; then update them match table1:
update table1 t1 inner join table2 t2 t1.a = t2.a set t2.b = t1.b, t2.c = t1.c, t2.d = t1.d, t2.e = t2.e;
Comments
Post a Comment