(Table1 inner join Table2) left outer (table3 inner join t4)



IBM's flagship relational database management system

(Table1 inner join Table2) left outer (table3 inner join t4)

Postby Raja190 » Sat May 21, 2016 1:22 pm

Hi All,

I'm trying to create query which performs (Table1 inner table2) left outer join (table3 inner table4). That is , I'm trying to get 2 columns. each column from 2 tables with co-relation values.

Sorry, I might be confusing, please see below SQL.

   SELECT T1.COLUMN1      
          ,T2.COLUMN1                      
                                               
   FROM    TABEL1   T1
   INNER JOIN     TABLE2   T2                              
           ON T1.ID = T2.ID

    LEFT OUTER JOIN                            
           TABLE3   T3
   ON  T3.ID = T4.ID
    AND T3.ID_VERSION    = T4.ID_VERSION
    AND T3.DATE = T4.DATE
   
 WHERE    T4.ID = T2.ID
      AND T4.ID_VERSION   = T2.ID_VERSION
      AND T4.STATE   = 'T'                      
      AND T2.ID  = '1991'                        
      AND T2.ID_VERSION      =                              
                     (SELECT MAX(ID_VERSION)                  
                      FROM TABLE2 T2
                      WHERE T2.ID = '1991')          
       AND T1.CODE1   = 0                      
       AND T1.CODE2   = 552;

 


This is not bringing me the right result or errors out. Please help to fix this.

Note: I'm trying to join TABLE1 & TABLE 2 get coumn1 result and joining TABLE3 & TABLE4 to get column (in left outer join as sometimes it might bring no results)
Raja190
 
Posts: 36
Joined: Mon Dec 14, 2015 8:13 pm
Has thanked: 0 time
Been thanked: 0 time

Re: (Table1 inner join Table2) left outer (table3 inner join

Postby Raja190 » Sat May 21, 2016 6:02 pm

Hi,


To simplify the question, i could say it as ((T1 and T2) or (T3 AND T4)). Here I'm pulling the result of T3 and T4 in left outer join as some its may get empty results.
Raja190
 
Posts: 36
Joined: Mon Dec 14, 2015 8:13 pm
Has thanked: 0 time
Been thanked: 0 time


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post