Jump to content

Mulitple Insert from table


scotchegg78

Recommended Posts

Hi guys.

 

I am updating a new counties for companys table and it uses a new reference table, so new ids etc.

 

currently I have tables ...

 

company_region (companyfk,regionfk)

region(id,name)

 

the new tables are for ease...

 

new_company_regions(companyid,countyid)

new_regions(id,countyname)

 

So how can I take from the current company_regions table the companyfk and insert this into new_company_region.compnayid with a new countyid where new_regions,countyname matches the old region.name ?

 

I think this makes sense??

 

Thanks for any help, just getting a little sticky with it.

Link to comment
Share on other sites

I'm not sure i quite understand but as best as i can, you want to take the contents of "company_region" and put it in "new_company_regions"?

 

if so, something like this might do it:

  INSERT INTO new_company_regions (companyid,countyid)
    SELECT company_region.companyfk, company_region.regionfk
    FROM company_region;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.