stored procedures - How to do MySQL Multi-insert from select statement -
so here basics of question. have selected result set join of 2 tables. result set series of id values , email addresses. each row in result set, want insert new row third table called timestamps
has timestamp now()
, id value result set, not email address. know can achieve running loop within stored procedure. additionally think cannot run insert into
statement because data inserting timestamps
not come result set in entirety, result set data decides number of rows must inserted , ids, while need return email addresses other processing. searching clever way avoid using loop this. possible? can generate dynamic insert statement? thank gives time or help.
suppose:
table1 columns: id
table2 columns: id, email
table1 , table2 linked column id
timestamps columns: id, time
then query be:
insert timestamps(id,time) select table1.id,now() table1 inner join table2 on table1.id = table2.id;
Comments
Post a Comment