php - Create a copy of a table mysql -
i trying create copy of table using code below. working great if both have same columns. table1 has 2 columns (id, username), while table2 has 3 columns (id, username, date). goal create copy of table1 table1.id = $id , insert date on in it. can guide me this?
insert table2 select * table1 table1.id = $id
example
table1 id,name,dateadded table2 name,id,dateoriginallyadded,someothercolumn query say
insert table2(name,id,dateoriginallyadded) select name,id,dateadded table1 ... specify both sets of columns, away with
insert table2 select name,id,dateadded,null table1 ... or
insert table2(id,name,dateoriginallyadded) select * table1 ... but can lead nasty bugs.
Comments
Post a Comment