mysql - SQL move part of table data and replace by key of row in new table -
example 2 tables:
table a: `id`, `a`, `b`, `c`, `x`, `y`, `z` table b: `id`, `h`, `i`, `j`, `x`, `y`, `z` i'm making table c contains x, y, z columns of either a , b, , use key link data i.e.:
a `id`, `a`, `b`, `c`, `id_c` b `id`, `h`, `i`, `j`, `id_c` c `id`, `x`, `y`, `z` creating these tables isn't problem.
problem have changing current data of a, b a, b, c.
how accomplish that?
the way can think of add id of a column in c while moving data, connect 2 tables , removing id column of a again. after same table b.
edit
i'm using mysql 4.1.22
as solution:
- create
table ccolumnsid, x, y, z(id auto-increment). - add data it, this:
insert c (x, y, z) select x, y, z ( select x, y, z union select x, y, z b) tempc - now
altertablesa,badding new columnid_c. - update
id_cthis:
update set id_c = (select id c c.x = a.x , c.y = a.y , c.z = a.z) - (after doing 4 both
a,b) dropx, y, za,b.
Comments
Post a Comment