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
https://forums.phpfreaks.com/topic/120168-mulitple-insert-from-table/
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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.