Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2006
    Posts
    11

    Unanswered: Subquery at Insert

    I'm going to insert new record to table 1, while one of the value I would like to do some select from other table to get the value, here is what my statement looks like:

    Code:
    Insert Into Table1(col1,col2,col3)values('1','a',x);
    Where the value x I would like to do Select which looks like this:

    Code:
    Select col6 From Table2 Where col1='abc';
    How do I join these two query so that it become one single subquery? THanks.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    insert
      into Table1
         ( col1
         , col2
         , col3 )
    select '1'
         , 'a'
         , col6
      from Table2
     where col1 = 'abc'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Oct 2006
    Posts
    11
    Sorry if I'm not stated clearly, the value '1' and value 'a' at the Insert statement I would like to define the value myself, whereby the value x is a value that I get from Select statement, where I select only one column from Table2 where the column1's value at Table2 will be 'abc'...

  4. #4
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    This is exactly what r937's statement does. You will need to replace '1' and 'a' with the value that you "define yourself" obviously.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •