IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Insert into a table by selecting from 2 tables


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
poongs
Warnings : 1

New User


Joined: 24 Jan 2007
Posts: 28
Location: pune

PostPosted: Tue May 13, 2008 9:49 am
Reply with quote

I have 3 tables say A, B and C. Tables A and B are similar with columns having same datatypes except that table B has an additional column. I would like to get the details of this additional colum from table C.

The functionality needs to be something like the one below

For ex, if table A has columns 1,2,3,4

Insert into A
(select 1,2,3 from table B (and for the 4th column) select 4 from table C)
Back to top
View user's profile Send private message
sainathvinod

New User


Joined: 01 Apr 2008
Posts: 11
Location: Chennai

PostPosted: Tue May 13, 2008 9:59 am
Reply with quote

Could you please make you question a bit more clear?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue May 13, 2008 10:25 am
Reply with quote

Hello,

To best receive suggestions that will provide a solution to your requirement, you need to post some sample rows from the tables and what the outcome should be of processing those rows.

Include both rows that will cause an insert in tableA and rows that will not. Once you show approprite data and clearly explain the "rules", you wil receive something useful rather than more questons.
Back to top
View user's profile Send private message
sainathvinod

New User


Joined: 01 Apr 2008
Posts: 11
Location: Chennai

PostPosted: Tue May 13, 2008 10:59 am
Reply with quote

Please try this query........ I'm not sure if my understanding is correct:-

INSERT INTO A
(SELECT B.1,
B.2,
B.3,
C.4
FROM B,C
WHERE B.(JOINING FIELD WITH TABLE C) = C.(CORRESPONDING JOINING FIELD WITH TABLE B)
)
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue May 13, 2008 11:10 am
Reply with quote

Hello Sainath,

Quote:
I'm not sure if my understanding is correct:-
I wasn't sure either icon_confused.gif Which is why i asked for clarification.

Hopefully, your understanding is correct icon_wink.gif

d
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top