Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I update two new tables from one old table.

Posted on 2013-12-29
4
Medium Priority
?
264 Views
Last Modified: 2014-01-22
Hello, I'm doing a data conversion from a old cart to a new one. I'm able to update the old customer info into the new table however with my new cart I have two tables.

Table 1: customers_new that has address, city, zip and general info.
Table 2: customers_stateprov_new that has the state id linked to it (data and structure below)

record_id | customer_state_customer_id |  customer_state_stateprov_id  | customer_state_destination

1 | 1000  | 37 | BillTo
2 | 1000  | 37 | ShipTo
3 | 1001  | 1   | BillTo
4 | 1001  | 1   | ShipTo

The old customer table has all of the info tied into the one table so I'm wanting to build out the customers_stateprov table with the old table data. I was able to export the old table to the new table following this basic query but as you can see it doesn't solve last step of building out the stateprov table

INSERT INTO tbl_new_customers (cust_id, cust_name, cust_addr1)
SELECT customer_id, customer_name, customer_address1
FROM tbl_old_customers
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
  • 2
4 Comments
 
LVL 9

Expert Comment

by:QuinnDex
ID: 39745085
a few questions that will help in solving your problem

how is the state saved in the old table.
does it have the id saved with it
was the state saved from a menu choice or did the user type in the state.
0
 

Author Comment

by:brihol44
ID: 39745211
    how is the state saved in the old table.

locState is the column name in the OLD TABLE and it has the 2 letter abbreviation so CA (for California). I was hoping I could just link it to my state table once I figured out the first step.  

My NEW STATE TABLE looks like...

state_prov_id | state_prov_code | state_prov_name

1  | CA | California
2  | OR | Oregon
3  | WA |Washington




    does it have the id saved with it


No, it just had a two state abbreviation like above.


   was the state saved from a menu choice or did the user type in the state.

it was a menu choice.
0
 
LVL 9

Expert Comment

by:QuinnDex
ID: 39745449
you will need to map either the name or the  2 letter abbreviation to you state ids,

the  state id's should relate to the state name somewhere in your new tables, as you used menu choice for your states in your old table you wont have spelling mistakes in the state name so you should be able match on the name.

if you are starting from scratch and the ids dont yet relate to a state then your first step will be to assign ids to each state then you will be able to import the data
0
 
LVL 24

Accepted Solution

by:
johanntagle earned 2000 total points
ID: 39750761
I assume customers_stateprov_new.record_id is auto_increment and state_destination is the column from the tbl_old_customers that will be used for customer_state_destination.  If I understand it correctly this should do it:

INSERT INTO customers_stateprov_new (customer_state_customer_id, customer_state_stateprov_id, customer_state_destination)
SELECT o.customer_id, s.state_prov_id, o.state_destination
FROM tbl_old_customers o 
JOIN state s ON (o.locState=s.state_prov_code);

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
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

721 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