Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

left join based on multiple fields

hi!

I have 2 tables that have 3 columns in common. i want to add the 4th column [DELTA] in table 2 to table 1 if the first 3 columns are the same as in table 1. here is what i wrote:

table_1:

LOAD
     LIQROW as PRICE,

     AMOUNT,

     BRANCH_CD as SPEED,

     UBR_CD as ID,

     CCY,

     FROM

[filename.xlsm]

(ooxml, embedded labels, table is [table 1]);

left join (table_1)
LOAD
     DELTA,

      BRANCH_CD as SPEED,

     UBR_CD as ID,

     [adjusted LCR LINE] as PRICE

[filename.xlsm]

(ooxml, embedded labels, table is [table 2]);

but it looks like certain rows in table 1 are double counted. do i need to add where clause?

6 Replies
swuehl
MVP
MVP

Are there any duplicate records in table 2 with same values for the three key fields? This would explain the multiplication of records in the joined table.

If yes, you need to decide how you want to handle this. Do these records show the same DELTA or a different DELTA?

Not applicable
Author

‌hi Vivienne

bphased on your script, table 2 will be left joined to table 1 based on only 2 columns - branch_cd and ubr_cd.

at the end of the script table 1 should contain all fields from table 1 originally as well as delta and price.

what do you mean by double counted? Can you give example?

Not applicable
Author

table 1:

ABC

D

1

iii

lv555
2

kkk

gucci666
3lllother222
ABCE
1iiilv12
2kkkother3
3mmmno brand4

I want to have everything in table 1 and add column e in table 2 to table 1 if all the values in col. a,b,c in table 2 match those in table 1. so my expectation is to get the below table after the code:

ABC

D

E

1

iii

lv55512
2

kkk

gucci6660
3lllother2220

but D looks like was double counted.. how can I get the above table?

table_1

LOAD A,

B,

C,

D

FROM [FILE.XLSM]

OOXML, embedded labels, table is table_1;

LEFT JOIN (table_1)

LOAD A,

B,

C,

E

FROM [FILE.XLSM]

OOXML, embedded labels, table is table_2;

Not applicable
Author

Hi Vivienne,

Your script looks fine. I would check the data if I were you.

If column D amount exactly double up, then chances are you have more than one row in table_2 with value a,iii,lv for column A, B, C respectively.


swuehl
MVP
MVP

Try a mapping approach:

MAP:

MAPPING

LOAD A&B&C, E

FROM [FILE.XLSM]

OOXML, embedded labels, table is table_2;

table_1

LOAD A,

B,

C,

D,

APPLYMAP('MAP', A&B&C, 0) as E

FROM [FILE.XLSM]

OOXML, embedded labels, table is table_1;

Not applicable
Author

hi Elly,

thank you so much for your reply! I checked my file and yes you are right. for table 1, it has multiple rows with the same values in col. A,B,C as it has total 11 columns and other columns distinguish the different rows. table 2 doesn't have that. if that's the case, should I use map instead of left join?

thanks,

Vivienne