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

Connecting 3 tables, and getting the output


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

New User


Joined: 04 May 2007
Posts: 20
Location: INDIA

PostPosted: Thu Nov 11, 2010 12:08 am
Reply with quote

I have three tables A, B, C. All these 3 tables have a common key column, say KEY.

Table - A, Columns - KEY, COL1, COL2
Table - B, Columns - KEY, COL1, COL2
Table - C, Columns - KEY, COL1, COL2

In the output result set, I wish to have few columns from A and few columns from C which has A.KEY = C.KEY AND a satisfying condition in table B.

I tried the below query, and it seems it is going to take days. Can someone help me fine-tune/re-write this query?

SELECT A.COL1, A.COL2, C.COL1
FROM A INNER JOIN C
ON
A.KEY = C.KEY
WHERE
A.KEY IN (SELECT KEY FROM B WHERE COL1 IN ('VAL1','VAL2')
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: Thu Nov 11, 2010 1:22 am
Reply with quote

Hello,

Suggest you consider eliminating unwanted rows from table B and then join only the rows you want with tables A/C. . .
Back to top
View user's profile Send private message
Mahendran3784

New User


Joined: 04 May 2007
Posts: 20
Location: INDIA

PostPosted: Thu Nov 11, 2010 1:32 am
Reply with quote

d.sch.,
Yeah, we dont want any rows from table B in the results set, just that table will be used for an extract criteria. I am trying the below query now. Will update you if I am successful?
SELECT A.COL1, A.COL2, C.COL1 FROM A INNER JOIN B ON A.KEY=B.KEY INNER JOIN C ON A.KEY=C.KEY WHERE B.COL1 IN ("VAL1", "VAL2")
I see this is also taking more time.
Thanks!
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: Thu Nov 11, 2010 2:19 am
Reply with quote

Hello,

Just because you use table criteria to eliminate most of the rows does not imply that any of the results have to be from table B.

If you don't want to use this kind of sql, you can always extract the useful rows from table to a sequential file and use this file to drive the sql that actually selects the rows you do want.
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 Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Joinkeys - 5 output files DFSORT/ICETOOL 7
No new posts Build a record in output file and rep... DFSORT/ICETOOL 11
No new posts XDC SDSF output to temp dataset CLIST & REXX 4
No new posts XL C Trace Preprocessor Output All Other Mainframe Topics 3
Search our Forums:

Back to Top