Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-05-26
4
Medium Priority
?
229 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 84

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this article, we’ll look at how to deploy ProxySQL.
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

609 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