Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
iJuanico
Contributor
Contributor

"LEFT JOIN" WITH "OR" CONDITIONAL

I have 4 tables: A, B, C and D, all have been loaded as QVD, I would like to make another table that reproduces the following query from the QVD already mentioned:

SELECT
D.portfoliocode_,
A.COD_GEST,
A.COD_INVEST_ADM,
A.COD_CLI,
A.AMT_FLAG_DEL,
A.DES_NME,
A.COD_CGC,
B.DAT_LIQ,
B.DAT_LANC,
B.DES_TYP,
C.DES_LAN,
B.DES_HIST,
B.AMT_VAL,
B.COD_REC_DESP,
B.COD_ACTV,
B.COD_ORIG,
B.COD_FLAG_LIQ

FROM A
INNER JOIN B
ON A.COD_CLI = B.COD_CLI
INNER JOIN C
ON C.COD_LAN = B.DES_TYP
LEFT JOIN D
ON (D.managercode_ = A.COD_GEST OR D.administratorcode_ = A.COD_INVEST_ADM)

 

My only question is to perform the "LEFT JOIN" with the "OR" conditional, could someone share an example?

Labels (3)
1 Reply
marcus_sommer

It's not possible in this (sql) way because all the joins are always only performed on identically field-names. This means you may need to apply one or multiple actions like:

  • you need to prepare your tables appropriately in beforehand
  • using some intermediates steps to adjust the tables on the fly
  • performing the join-loads multiple times (in your case the left join might be performed twice - for each OR part
  • depending on the requirements the pure join-statements might be combined with where-clauses
  • using of (nested) mappings instead of joins

- Marcus