0

All, so I am trying to run the query. The query consist of 7 tables and I want to all table get left joined based on A.conn_keyy and the others with clause 'ON'

My confusion comes when I want to join CPLCUR based on A , not works.

(CPLCUR.conn_keyy in ( a.conn_keyy = b.conn_keyy )

It appears error : both left and right aliases encountered in join 'conn_key'

set hive.support.quoted.identifiers=none;
select 
coalesce(a.conn_keyy, b.conn_keyy,CPLCUR.conn_keyy) as rrconn_keyy,
b.rfbbn, b.LINES_ID,b.TYPE,CPLCUR.*

FROM
(tablee.aa)A

LEFT OUTER JOIN 
(tablee.bb) B 
ON (A.conn_keyy = B.conn_keyy)

LEFT OUTER JOIN (SELECT `(c21)?+.+` FROM tablee.cc ) CPLCUR
ON (CPLCUR.conn_keyy in ( a.conn_keyy = b.conn_keyy )
AND CPLCUR.cllt = REGEXP_EXTRACT(B.rfbbn,'^(?:[^*]*\\*){2}([^*]*)',1))

LEFT OUTER JOIN (SELECT DISTINCT * FROM tablee.dd) CPLBAL
ON CPLBAL.conn_keyy = A.conn_keyy
AND CPLBAL.SEQUENCE = CPLCUR.SEQUENCE
AND CPLBAL.dtdt = '1999' 

LEFT OUTER JOIN
 (tablee.REP)REP 
ON REP.relino = B.lnido

LEFT OUTER JOIN tablee.P PRD
ON PRD.PRODUCT_CODE = REGEXP_EXTRACT(A.conn_keyy,'[.]([^.]+)',1)
AND PRD.dtdt = '1999'

WHERE B.lnido LIKE 'PLCONS1%'
) rrvv;

What is best practice to get this?

The desired results:
+-----------+---------+--------+----------+-------------+-------+-----+-----+
| conn_keyy | b.rfbbn | b.LINES| b.TYPE   |   CPLCUR    | CPLBAL| REP | PRD |
+-----------+---------+--------+----------+-------------+-------+-----+-----+
| 111       | aaa     | PCOS1% | bbsr     | 2019-02-21  |       |     |     |
| 200       |         | PCOS1% | ny       | X           |       |     |     |
| 222       | bbb     | PCOS1% | pp       | Y           |       |     |     |
| 300       | rrr     | PCOS1% | atl      | 2019-03-18  |       |     |     |
| 333       | ccc     | PCOS1% | dd       | Z           |       |     |     |
| 400       | vvv     | PCOS1% | tt       | 2019-03-18  |       |     |     |
+-----------+---------+--------+----------+-------------+-------+-----+-----+
  • 1
    Perhaps you could simplify your query and provide sample data and desired results. Your query is a bit complicated for what looks like a rather specific question. – Gordon Linoff Jan 13 '21 at 16:11
  • Honestly I am trying to get the same results like this https://stackoverflow.com/questions/55225131/hive-full-outer-join-returning-multiple-rows-for-same-join-key?noredirect=1#comment116146904_55225131 – thecardcaptor Jan 13 '21 at 16:37
  • 1
    also can you explain what are you trying to get as reesult by this join condition : `(CPLCUR.conn_keyy in ( a.conn_keyy = b.conn_keyy )` , can you explain it in plain english – eshirvana Jan 13 '21 at 16:41
  • hem, so i am trying to get only a.conn_key as the base conn_key (so i have to join A.conn_key = B.conn_key = CPLCUR.connkey). The value of CPLCUR.conn_key, B.connkey should be same as A.conn_key. (no duplicates) – thecardcaptor Jan 13 '21 at 17:09
  • So why not simply use `ON CPLCUR.conn_keyy = a.conn_keyy`? – Fred Jan 13 '21 at 23:32
  • My expectation doesnt meet the sum results. Based n the link I attached, I have to join with the 2 of previous conn_key to meet the results. still find. – thecardcaptor Jan 14 '21 at 00:17
  • Why not ON CPLCUR.conn_keyy = b.conn_keyy? (join with tableB ). BTW the link you are referring is a question without accepted answer – leftjoin Jan 14 '21 at 08:41
  • but i want the same result as his/her.. – thecardcaptor Jan 14 '21 at 09:27
  • but i want the same result as his/her and dont mention the acepted answer.. – thecardcaptor Jan 14 '21 at 09:28
  • it is not clear what are you trying to do without minimal reproducible data example. Try to prepare few small datasets and explain the result. – leftjoin Jan 14 '21 at 15:25

0 Answers0