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:

  1. create table c columns id, x, y, z (id auto-increment).
  2. add data it, this:
insert c (x, y, z) select x, y, z (     select x, y, z     union     select x, y, z b) tempc 
  1. now alter tables a , b adding new column id_c.
  2. update id_c this:
update set id_c = (select id c c.x = a.x , c.y = a.y , c.z = a.z) 
  1. (after doing 4 both a , b) drop x, y, z a , b.

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -