Jump to content

Insert to table from table - mulitple rows fail....


scotchegg78

Recommended Posts

HI guys,

 

My code here fails as there are multiple rows, I thought this should work??

 

insert into company_sa_country(countryid,companyid) VALUES ('1',(SELECT companyfk FROM company_region cr WHERE cr.regionfk = '94'))

 

ITs simply taking companys with old region ids that are 94 and placing them the new table with ids 1.

 

thanks for any info.

 

Link to comment
Share on other sites

well it should haev multiple rows if the SELECT returns multiple rows

 

I believe it will treat your string value '1' as a constant and pair it with the number of matching results for the select query.

 

If its giving an error that message would be advantageous to solving your problems, otherwise its working as its built, maybe not as you like.

 

If you need to select only 1 specific company then you need to have a stronger where clause or apply a LIMIT to your query.

Link to comment
Share on other sites

Hi thanks for reply.

 

It should return multiple rows, but it fails with this multiple rows error?

 

I need to it to insert all rows from the table with the id 94 into the new table with its company ID and a new forein key as 1.

 

Like the query is laid out, only it wont run :(

 

if it help here is the table info..

 

From table... company_region (id,companyfk,regionfk)

to table  .. company_sa_county(id,companyid,countyid).

 

ids's are auto, companyfk and companyid are the same company id values, and i replace regionfk where 94 with 1 into company_sa_county.

 

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.