Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

LEFT JOIN DOUBLES THE COUNT

Hi,

I'm new to Qlikview. trying to link 2 tables together. here are how the tables look

table 1:

ABC

D

1

iii

lv555
2

kkk

gucci666
3lllother222
ABCE
1iiilv12
2kkkother3
3lllno brand4

table 2:

I want to add col. E in table 2 to col. D in table 1 if col. A,B,C are the same in both tables.

sorry for the confusion!! made some changes: B should be iii.

EDIT:

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


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;

how can I get it work?

Message was edited by: vivienne li

8 Replies
swuehl
MVP
MVP

Not sure if I understand the issue.

Your sample data above does not seem to have common key values in both tables. So there shouldn't be E values joined to table_1. Do you see joined values with these data? And what do you mean with 'doubles the count'?

qlikviewwizard
Master II
Master II

What is your required output? Thank you.

Not applicable
Author

Hi Vivienne,

Qlikview will use as a key all fields with a common name.

First you need to determine what is your key.

The Key MUST be unique. If not you will get duplication.

Let's assume you want join on the A field.

table_1

LOAD A,

B,

C,

D

FROM [FILE.XLSM]

OOXML, embedded labels, table is table_1;

LEFT JOIN (table_1)

LOAD A,

E

FROM [FILE.XLSM]

OOXML, embedded labels, table is table_2;

will give you:

ABC

D

E

1

jjj

lv55512
2

kkk

gucci6663
3lllother2224

Let's assume now your key is A,B and C.

You will have duplication because the values in B and C are differents in table 1 and 2.

Another option is the renaming technic:

table_1

LOAD A,

B,

C,

D

FROM [FILE.XLSM]

OOXML, embedded labels, table is table_1;

LEFT JOIN (table_1)

LOAD A,

B as B_in_T2,

C as C_in_T2,

E as E_in_T2

FROM [FILE.XLSM]

OOXML, embedded labels, table is table_2;

ABB_in_T2CC_in_T2

D

E

1

jjj

iiilvlv55512
2

kkk

kkkgucciother6663
3llllllotherno brand2224

Let me know if it's help.

Cheers.

Eva

jagan
Luminary Alumni
Luminary Alumni

HI,

Try like this

Temp:

LOAD A,

B,

C,

D

FROM [FILE.XLSM]

OOXML, embedded labels, table is table_1;

LEFT JOIN (Temp)

LOAD A,

B,

C,

E

FROM [FILE.XLSM]

OOXML, embedded labels, table is table_2;

Data:

LOAD

A,

B,

C,

E AS D

RESIDENT Temp;

DROP TABLE Temp;

In both the tables only first row is matching, so you will get 12 in Column D other values are null.

Hope this helps you.

Regards,

Jagan.

jagan
Luminary Alumni
Luminary Alumni

Note: The combination of ABC should be unique in the Table 1, otherwise you will get duplicate records.

Regards,

Jagan.

Not applicable
Author

apologize for the confusion. there were some typos in the original post.

table 1:

ABC

D

1

iii

lv555
2

kkk

gucci666
3lllother222
ABCE
1iiilv12
2kkkother3
3lllno 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;

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;

maxgro
MVP
MVP

if you have duplicate A B C in T1 but not in T2, there isn't any problem; 5 records in T1 at the beginning of the script and 5 records at the end

// dupl

T1:

load * inline [

A,B,C,D

1,iii,lv,555

1,iii,lv,555

1,iii,lv,555

2,kkk,gucci,666

3,lll,other,222

];

// no dupl

T2:

load * inline [

A,B,C,E

1,iii,lv,12

2,kkk,other,3

3,lll,no brand,4

];

left join (T1)

load A, B, C, E

Resident T2;

T1:

1.png

if you have duplicated (and matching) A B C in T2 you have duplicated records also at the end of the script execution (3 records in T1 at the start of the script, 4 at the end)

// no dupl

T1:

load * inline [

A,B,C,D

1,iii,lv,555

2,kkk,gucci,666

3,lll,other,222

];

// dupl

T2:

load * inline [

A,B,C,E

1,iii,lv,12

1,iii,lv,1200

2,kkk,other,3

3,lll,no brand,4

];

left join (T1)

load A, B, C, E

Resident T2;

T1:

2.png