Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
jessica_webb
Creator III
Creator III

Joining multiple tables

  Really hoping someone can help here as I am VERY stuck!

I am trying to keep all of my data (from several source) in one table. No idea if that's good practice, but I find it easier.

I load my first table:

Data:

LOAD

ID,

Name,

Age

From.....source1

Then next table:

Data:

LOAD

ID,

Name,

Age

From.....source2

All seems ok.

Then, I  match in more data:

tempData1:

CrossTable(Given, Target, 1)

LOAD

ID,

A,

B,

C

From...source3

JOIN (Data) LOAD*,

ApplyMap('Map_A',Given) as New

Resident tempData1;

Drop TABLE tempData1;

Drop FIELD Given;

Then the last bit of data:

tempData2:

CrossTable(Given, Target, 1)

LOAD

ID,

D,

E,

F

From...source4

JOIN (Data) LOAD*,

ApplyMap('Map_A',Given) as New

Resident tempData2;

Drop TABLE tempData2;

Drop FIELD Given;

And here it all goes wrong!

What I expect to see is (where 'Given' actually no longer exists - just showing it for clarity):

IDNameAgeNewTargetGiven
INJTom42Green4A
WMHSarah31Yellow2B
QMIIan51Blue5C
WXILaura28Yellow8D
OWMBen97Green5E
MQYPaul24Blue7F

What I actually see is:

IDNameAgeNewTargetGiven
INJTom42Green4A
WMHSarah31Yellow2B
QMIIan51Blue5C
WXILaura28
OWMBen97
MQYPaul24
WXI--Yellow8D
OWM--Green5E
MQY--Blue7F

Can someone please tell me where I'm going wrong?? Why does it match the first temp table in ok, but not the second?

Thanks,
Jess

1 Solution

Accepted Solutions
sunny_talwar

May be we don't need that part, try this

Data:

LOAD

ID,

Name,

Age

From.....source1

Data:

LOAD

ID,

Name,

Age

From.....source2

tempData1:

CrossTable(Given, Target, 1)

LOAD

ID,

A,

B,

C

From...source3

tempData2:

CrossTable(Given, Target, 1)

LOAD

ID,

D,

E,

F

From...source4


Concatenate (tempData1)

LOAD*Resident tempData2;


DROP TABLE tempData2;

JOIN (Data) LOAD*,

ApplyMap('Map_A',Given) as New

Resident tempData1;

Drop TABLE tempData1;

Drop FIELD Given;

View solution in original post

7 Replies
sunny_talwar

Concatenate before you join to data

Data:

LOAD

ID,

Name,

Age

From.....source1

Data:

LOAD

ID,

Name,

Age

From.....source2

tempData1:

CrossTable(Given, Target, 1)

LOAD

ID,

A,

B,

C

From...source3

Concatenate(tempData1)

CrossTable(Given, Target, 1)

LOAD

ID,

D,

E,

F

From...source4

JOIN (Data) LOAD*,

ApplyMap('Map_A',Given) as New

Resident tempData1;

Drop TABLE tempData1;

Drop FIELD Given;

MarcoWedel

Hi,

after the first join the Data table already has the Given and Target fields thus preventing a subsequent join on just ID like you expected.

hope this helps

regards

Marco

jessica_webb
Creator III
Creator III
Author

Hi Sunny,

Thanks for the response.

I've tried this and am getting the error 'Illegal combination of prefixes' when the script gets to the 'Concatenate' part. From reading online, it seems because you can't concatenate a crosstable.

I've now changed it to

Data:

LOAD

ID,

Name,

Age

From.....source1

Data:

LOAD

ID,

Name,

Age

From.....source2

tempData1:

CrossTable(Given, Target, 1)

LOAD

ID,

A,

B,

C

From...source3

tempData2:

CrossTable(Given, Target, 1)

LOAD

ID,

D,

E,

F

From...source4


Concatenate (tempData1)

LOAD*Resident tempData2;


DROP TABLE tempData2;

JOIN (Data) LOAD*,

ApplyMap('Map_A',Given) as New

Resident tempData1;

Drop TABLE tempData1;

Drop FIELD Given;

But get a 'Table not found' error when it gets to Concatenate..

Any ideas?

Thanks,

Jess

sunny_talwar

May be we don't need that part, try this

Data:

LOAD

ID,

Name,

Age

From.....source1

Data:

LOAD

ID,

Name,

Age

From.....source2

tempData1:

CrossTable(Given, Target, 1)

LOAD

ID,

A,

B,

C

From...source3

tempData2:

CrossTable(Given, Target, 1)

LOAD

ID,

D,

E,

F

From...source4


Concatenate (tempData1)

LOAD*Resident tempData2;


DROP TABLE tempData2;

JOIN (Data) LOAD*,

ApplyMap('Map_A',Given) as New

Resident tempData1;

Drop TABLE tempData1;

Drop FIELD Given;

jessica_webb
Creator III
Creator III
Author

Hi Sunny,

I'd tried a fix of:

NoConcatenate

LOAD*Resident tempData1;

Concatenate(tempData1)

LOAD*Resident tempData2;

DROP TABLE tempData2;

Which worked. But removing it all together like you've suggested works too...

I'm confused. How does QV know to apply map to tempData2??

sunny_talwar

Since the two crosstables have the exact same names, it autoconcatenates the two. So when you put noconcatenate and then concatenate you are basically adding extra overhead here.

jessica_webb
Creator III
Creator III
Author

Of course! The field names are becoming values with the cross table function, so that makes sense!

Thanks so much for your help!