?
Solved

How can I update/add existing data from one set of tables to another?

Posted on 2013-05-26
4
Medium Priority
?
228 Views
Last Modified: 2013-05-27
Hello,

I have a old set of tables that I want to import into a new set of tables from. I've copied the old tables into the new db to make thing easier but the table structure is a little different for the new tables.

How can I copy the data from the old tables into the new ones?

So for example...

OLD TABLE REF
tbl_old_customers
tbl_old_orders


NEW TABLE REF
tbl_new_customers
tbl_new_orders


OLD TABLE CUSTOMERS: customer_id, customer_name, customer_address1, customer_city => NEW TABLE CUSTOMERS: cust_id, cust_name, cust_addr1

OLD TABLE ORDERS: customer_id, order_date, order_payment_type => NEW TABLE ORDERS: cust_id, ord_date, pay_type

Thanks for the help, I believe once somebody shows me how to do the customers table, I can figure out the orders table unless there's some sort of inner join process that can happen to do both.

Brian
0
Comment
Question by:brihol44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 16

Assisted Solution

by:santoshmotwani
santoshmotwani earned 668 total points
ID: 39198509
INSERT INTO new_table_customers
            (cust_id,
             cust_name,
             cust_addr1)
SELECT *
FROM   (SELECT customer_id       AS cust_id,
               customer_name     AS cust_name,
               customer_address1 AS cust_addr1
        FROM   old_table_customers);
0
 
LVL 6

Assisted Solution

by:Peter Kiprop
Peter Kiprop earned 664 total points
ID: 39198540
Try the below

insert into tbl_new_customers
select  customer_id, customer_name, customer_address1 from tbl_old_customers

insert into tbl_new_orders
select  customer_id, order_date, order_payment_type from tbl_old_orders
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 668 total points
ID: 39198548
I just had to do this earlier this evening.  This is what I used from http://stackoverflow.com/questions/7482443/how-to-copy-data-from-one-table-to-another-new-table-mysql  Note that the order and number of fields must match just like they would on a normal INSERT.
INSERT INTO tbl_new_customers (cust_id, cust_name, cust_addr1)
SELECT customer_id, customer_name, customer_address1
FROM tbl_old_customers

Open in new window

0
 

Author Closing Comment

by:brihol44
ID: 39199310
Thanks everyone!

Brian
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question