If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > DB2 Query help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-20-05, 14:02
panchopp panchopp is offline
Registered User
 
Join Date: Aug 2004
Location: Buenos Aires, Argentina
Posts: 28
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.
Reply With Quote
  #2 (permalink)  
Old 12-20-05, 15:29
panchopp panchopp is offline
Registered User
 
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!!!
Reply With Quote
  #3 (permalink)  
Old 12-20-05, 16:50
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On