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 

Need Help on SQL JOIN on five Tables

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


Joined: 30 Jan 2007
Posts: 1
Topics: 1

PostPosted: Thu Feb 01, 2007 10:23 pm    Post subject: Need Help on SQL JOIN on five Tables Reply with quote

Hi

Need a SQL Query:

I have five input tables. Applicant, App_Addr, Address, Bureau and Closure

Input:

Code:

APPLICANT Table
APPL_ID (PK)
GOVT_NBR
NAME

APP_ADDR Table
APPL_ID (FK)
ADDR_ID (FK)

ADDRESS Table
ADDR_ID (PK)
ADDRESS_LINE1
CITY

BUREAU Table
APPL_ID (FK)
CLS_ID (FK)

CLOSURE Table
CLS_ID (PK)
RPT_GOVT-NBR
RPT_CLS_FI-NUM


I need to pull data from all tables based on the WHERE clause and also need additional CLOSURE Table data for that APPL_ID

Please let me know whether below query works or not. Thanks
Code:

EXEC SQL                       
   SELECT  A.APPL_ID   
                A.NAME
                C.ADDRESS_LINE1
                C.CITY
                E.RPT_GOVT_NBR
                E.RPT_CLS_FI_NUM
   FROM APPLICANT A
   INNER JOIN APP_ADDR  B
   ON A.APPL_ID = B.APPL_ID
   INNER JOIN ADDRESS C
   ON B.ADDR_ID  =  C.ADDR_ID
   INNER JOIN BUREAU D
   ON A.APPL_ID = D.APPL_ID
   INNER JOIN CLOSURE E
   ON D.CLS_ID  =  E.CLS.ID
   WHERE A.GOVT_NBR          = :GOVT-NBR
   AND    C.ADDRESS_LINE1  = :LINE1
   AND    C.CITY                   = :CITY
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12380
Topics: 75
Location: San Jose

PostPosted: Fri Feb 02, 2007 5:13 pm    Post subject: Reply with quote

nandra2180,

Try this link

Code:

   SELECT A.APPL_ID   
         ,A.NAME
         ,C.ADDRESS_LINE1
         ,C.CITY
         ,E.RPT_GOVT_NBR
         ,E.RPT_CLS_FI_NUM
     FROM APPLICANT A
         ,APP_ADDR  B
         ,ADDRESS   C
         ,BUREAU    D
         ,CLOSURE   E
    WHERE A.APPL_ID        =  B.APPL_ID
      AND B.ADDR_ID        =  C.ADDR_ID
      AND A.APPL_ID        =  D.APPL_ID
      AND D.CLS_ID         =  E.CLS.ID
      AND A.GOVT_NBR       = :GOVT-NBR
      AND C.ADDRESS_LINE1  = :LINE1
      AND C.CITY           = :CITY



Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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