Inserting foreign key value

  • Hi There,

    Please suggest best way to do this

    insert into table(value1,value2)

    values ('123', select id from table where section='section 1')

    value2 is the foreign key value from the second table

    but this doesnt work,i have to declare a variable and set the above select value into the variable

    and replace this above select statement with the variable

    Please suggest best way to achieve this

    Thanks

  • forum member (1/31/2010)


    Hi There,

    insert into table(value1,value2)

    values ('123', select id from table where section='section 1')

    Try this instead.

    insert into table(value1,value2)

    SELECT '123', id from table where section='section 1'

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply