Using INSERT SELECT to copy & populate one table from another.

Using INSERT SELECT to copy & populate one table from another.

Open the destination database - where you want the new records to be:

Execute the following type of example to insert records from your 


INSERT INTO current_db_name.dest_table(id, user_id, billed, billable, invoice_id, client_id, client_projects_id, time_in, time_out, ttl_hrs, subj, descr, notes, created )
SELECT `origin_table`.`id`,
    `origin_table`.`author` as 'user_id',
    `origin_table`.`billed`,
    `origin_table`.`billable`,
    `origin_table`.`invoice_id`,
    `origin_table`.`cust_id` as 'client_id',
    `origin_table`.`proj_id` as 'client_projects_id',
    `origin_table`.`time_in`,
    `origin_table`.`time_out`,
    `origin_table`.`ttl_hrs`,
    `origin_table`.`subj`,
    `origin_table`.`descr`,
    `origin_table`.`notes`,
    `origin_table`.`tstamp` as 'created'
    
FROM `origin_database`.`origin_table`;

Share this Post