sql - mySQL moving rows from 2 tables to other tables -
hello can't seem figure out why sql statement doesn't work?
i trying move rows table1 , table2 table3 , table4. thought easiest approach selecting rows inner join , making 2 insert into.
begin; insert table3 (id, content, createdby, createddate, endtime, starttime) values (table1.id, table1.content, table1.createdby, table1.createddate, table1.endtime, table1.starttime); insert table4 (table3_id, sometableid) values (table2.table3_id, table2.sometableid); select table1.id, table1.content, table1.createdby, table1.createddate, table1.endtime, table1.starttime, table2.table2_id, table2.sometableid table1 inner join table2 on table1.id = table2.table1_id table1.endtime < now() commit;
when run sql outputs #1054 - unknown column 'table1.id' in 'field list'
if has ideas, or can point me in right direction appreciated!
use insert ... select
:
insert table3 (id, content, createdby, createddate, endtime, starttime) select id, content, createdby, createddate, endtime, starttime table1 endtime < now(); insert table4 (table3_id, sometableid) select t2.table2_id, t2.sometableid table1 t1 join table2 t2 on t1.id = t2.table1_id t1.endtime < now();
Comments
Post a Comment