MySQL Forums
Forum List  »  Newbie

Insert keys from 1 table into 2 others.
Posted by: M F
Date: March 14, 2012 05:47PM

I am creating a table which will be used by 2 other tables.


NEWTABLE has 2 columns: ID (autoincrement) and VALUE
TABLEA gets new column: NEWTABLE_ID, old columns: ID, AVALUE
TABLEB gets new column: NEWTABLE_ID, other columns: ID, BVALUE

I add new rows to NEWTABLE for TABLEA and TABLEB with 2 statements: (ID gets auto value)

SELECT 'default' from TABLEA

SELECT 'default' from TABLEB

Now NEWTABLE has X number rows where X is number of rows in TABLEA + TABLEB.

Say n is the number of rows in TABLEA

I want to update NEWTABLE_ID in TABLEA with the first n values of NEWTABLE and then update TABLEB with x-n values. Please tell me how to do this, it doesn't have to be in just one statement.

I could also have updated NEWTABLE_ID in TABLEA and TABLEB before inserting rows to the new table but not sure how to do that either. If you have a solution for that instead, that would be great as well.


Edited 1 time(s). Last edit at 03/14/2012 05:45PM by M F.

Options: ReplyQuote

Written By
Insert keys from 1 table into 2 others.
March 14, 2012 05:47PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.