MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Question on Query

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
edkir98
Beginner


Joined: 27 Aug 2007
Posts: 102
Topics: 42
Location: Chennai

PostPosted: Thu Jul 30, 2009 10:30 am    Post subject: Question on Query Reply with quote

i have 4 tables. 3 of them have to be inner joined to obtain the list of accounts and some account details after applying a lot of filter conditions on the 3 tables. Then i need to do left outer join with the 4th table on the account number.

The 3 tables for inner join have 100000 rows each and the fourth table is a Child table which contains 85000 rows. In all the tables ACCT_No is the common reference.

When i apply the filter conditions on the 3 tables only 5 out of 100000 records are qualified and i would like to left outer join only these 5 or less rows with the 4th table.

My query is, is it possible to filter out the 5 rows alone in table 4 before i do left outer join?

A Example

Code:
SELECT  RESULT1.COLX
       ,RESULT1.COL1
       ,RESULT1.COL2         
       ,RESULT1.COL3
       ,RESULT2.COL4
FROM
(    (   SELECT     A.COLX
      ,A.COL1
      ,B.COL2
      ,C.COL3
     FROM    TABLE_A A
      ,TABLE_B B
      ,TABLE_C C
    WHERE    (There are a number of filter conditions on the 3 tables)
       AND    A.COLX = B.COLY
       AND    B.COLY = C.COLZ                    
    )    AS RESULT1
LEFT OUTER JOIN
    (
   SELECT     D.COLX
      ,D.COL4
     FROM    TABLE_D D
     WHERE   (some filter conditions on Table_D)
--What i wanted to do here is instead of having the whole table to participate in the LEFT OUTER JOIN
--i would want only the 5 rows to participate.
    )    AS RESULT2
ON  RESULT1.COLX = RESULT2.COLX
)


Can someone please help.

Did i make my question Clear..
_________________
Thanks
Back to top
View user's profile Send private message Yahoo Messenger
edkir98
Beginner


Joined: 27 Aug 2007
Posts: 102
Topics: 42
Location: Chennai

PostPosted: Tue Aug 04, 2009 8:26 am    Post subject: Reply with quote

Its not possible to do this with SQL or Dint i make my question clear..
_________________
Thanks
Back to top
View user's profile Send private message Yahoo Messenger
CZerfas
Intermediate


Joined: 31 Jan 2003
Posts: 211
Topics: 8

PostPosted: Wed Aug 05, 2009 3:36 am    Post subject: Reply with quote

To my eyes your query looks fine and should do what you want. Is EXPLAIN showing, that your first subselect is executed as the first query block?

regards
Christian
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group