简体   繁体   中英

How to write a transitive sql join in DB2?

I want something like the following.

SELECT fewCols, aColFromNewTbl FROM TABLE_A AS A 
LEFT OUTER JOIN TABLE_B AS B ON A.ID = B.ID
LEFT OUTER JOIN TABLE_C AS C ON A.ID = C.ID
INNER JOIN A_NEW_TABLE AS NEWTBL ON NEWTBL.ID = B.ID;

Somehow I'm not able to achieve this functionality. Actually above query is suppose to join A with NEWTBL , but I'm joining it with B , which is already joined with A . For my results I want them to come exclusively from the join of NEWTBL and B . I don't know how I can get desired results?

Probably you need this:

SELECT fewCols, aColFromNewTbl
FROM TABLE_A AS A 
LEFT OUTER JOIN TABLE_B AS B
    INNER JOIN A_NEW_TABLE AS NEWTBL
    ON NEWTBL.ID = B.ID
ON A.ID = B.ID
LEFT OUTER JOIN TABLE_C AS C
ON A.ID = C.ID;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM