Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2003
    Location
    canada
    Posts
    230

    Unanswered: INSERT INTO between two tables!!!! please help

    I am working with db2 v8.2 and aix 5.2,

    I have two tables like this:
    tab1(id,t1d,t1n,t1m,t2d,t2n,t2m,t3d,t3n,t3m) id is PK
    tab2(id,d,n,m) id is PK and table is empty

    I need insert from tab1 into tab2 such that t1d,t2d,t3d insert into d
    and t1n,t2n,t3n into n and t1m,t2m,t3m into m.

    Thank you inadvance for your help.

  2. #2
    Join Date
    Mar 2004
    Location
    Toronto, ON, Canada
    Posts
    513
    Can you give a few example rows? I'm not entirely sure what you're trying to do.

    Specifically:
    " t1d,t2d,t3d insert into d" -> how do 3 columns become 1 in the new table?
    --
    Jonathan Petruk
    DB2 Database Consultant

  3. #3
    Join Date
    Sep 2003
    Location
    canada
    Posts
    230
    Quote Originally Posted by J Petruk
    Can you give a few example rows? I'm not entirely sure what you're trying to do.

    Specifically:
    " t1d,t2d,t3d insert into d" -> how do 3 columns become 1 in the new table?
    Hi J Petruk,
    I did not mean we insert three values to one column in one row, but it is possible in three rows.

  4. #4
    Join Date
    Mar 2004
    Location
    Toronto, ON, Canada
    Posts
    513
    Do just you mean this, then?

    INSERT INTO TAB2 SELECT ID, T1D, T1N, T1M FROM TAB1;
    INSERT INTO TAB2 SELECT ID, T2D, T2N, T2M FROM TAB1;
    INSERT INTO TAB2 SELECT ID, T3D, T3N, T3M FROM TAB1;
    --
    Jonathan Petruk
    DB2 Database Consultant

  5. #5
    Join Date
    Sep 2003
    Location
    canada
    Posts
    230
    Quote Originally Posted by J Petruk
    Do just you mean this, then?

    INSERT INTO TAB2 SELECT ID, T1D, T1N, T1M FROM TAB1;
    INSERT INTO TAB2 SELECT ID, T2D, T2N, T2M FROM TAB1;
    INSERT INTO TAB2 SELECT ID, T3D, T3N, T3M FROM TAB1;
    It backed to me error

    DB21034E The command was processed as an SQL statement because it was not a
    valid Command Line Processor command. During SQL processing it returned:
    SQL0412N Multiple columns are returned from a subquery that is allowed only
    one column. SQLSTATE=42823

  6. #6
    Join Date
    Mar 2004
    Location
    Toronto, ON, Canada
    Posts
    513
    Hurumph, should work. Post your sql and table defs.
    --
    Jonathan Petruk
    DB2 Database Consultant

  7. #7
    Join Date
    Sep 2003
    Location
    canada
    Posts
    230
    Quote Originally Posted by J Petruk
    Hurumph, should work. Post your sql and table defs.
    I was wrong and your suggestion worked very well .

    Thank you again fro your help.

Posting Permissions

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