Results 1 to 3 of 3

Thread: DB2 Query help

  1. #1
    Join Date
    Aug 2004
    Location
    Buenos Aires, Argentina
    Posts
    28

    Unanswered: DB2 Query help

    Good morning / afternoon all.
    I need to perform the following task within one table. I will put an example to make it easier.

    Table1: IDCol, DescCol, DescCol2
    1 BLA PF1
    1 BLE PF2
    2 CA PF3
    3 CE PF4

    I need to create a QUERY that will insert new rows, with IDCol=4, but copying the values of the DescCol and DescCol2 of the rows with IDCol=1. So it should introduce two new rows, and the end table would be:

    Table1: IDCol, DescCol, DescCol2
    1 BLA PF1
    1 BLE PF2
    2 CA PF3
    3 CE PF4
    4 BLA PF1
    4 BLE PF2



    Thanks in advance.

  2. #2
    Join Date
    Aug 2004
    Location
    Buenos Aires, Argentina
    Posts
    28
    It should be sth like:

    INSERT INTO TABLE1 (IDCol, DescCol, DescCol2)
    VALUES (4,
    SELECT DescCol, DescCol2 from TABLE1 where IDcol = 1
    )

    But this query is not working for me. Could you please point out an alternative to this query (or if there is sth to correct in this one?)
    Thank you!!!

  3. #3
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    INSERT INTO TABLE1 (IDCol, DescCol, DescCol2)
    SELECT 4, DescCol, DescCol2 from TABLE1 where IDcol = 1
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

Posting Permissions

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