Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Insert into a table by selecting from 2 tables

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Insert into a table by selecting from 2 tables
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    Post subject:
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

Site Director


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

PostPosted: Tue May 13, 2008 10:25 am    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Tue May 13, 2008 11:10 am    Post subject: Reply to: Insert into a table by selecting from 2 tables
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SPUFI -- Joining 3 tables – data in... Sysaron DB2 2 Wed Mar 08, 2017 4:18 am
No new posts To know activities on db2 tables ashek15 DB2 4 Fri Mar 03, 2017 11:23 pm
No new posts how to send just 10 rows in a CICS sc... Megha Gupta CICS 5 Thu Feb 23, 2017 6:57 pm
No new posts ERM-Diagram of SysIBM-Catalog-Tables Auryn DB2 2 Fri Feb 17, 2017 6:22 pm
No new posts Join of more than one table dibyendumandal11111 DB2 6 Mon Feb 13, 2017 11:36 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us