Forum Moderators: coopster

Message Too Old, No Replies

Appending records in separate but related tables

         

LemonFizz

3:12 pm on Mar 30, 2004 (gmt 0)

10+ Year Member



Hi.
I have two related tables:
User
Product
the primary key user_id is a foreign key in Product.
I need to do a select to find a particular user (easy) then use that resultset to automatically insert the user_id in the User table into a new Product record. i.e. appending a product to a user
Any idea how to do this.
Many thanks
LF

LemonFizz

3:36 pm on Mar 30, 2004 (gmt 0)

10+ Year Member



Actually I solved this by searching in this forum for a bit longer
the answer is here
[webmasterworld.com...]

ara818

10:06 am on Apr 3, 2004 (gmt 0)

10+ Year Member



If you're using a DB that allows sub-selects (NOT MySQL IIRC) you can do something like:

insert into products values(v1, v2, v3, (select user_id from users where user_id = x));