Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Death4Free
Contributor III
Contributor III

Lookup from different data sources

Hi! What is the best way to do the following:

I have:

DataSource1 - Table A;

DataSource2 - Table B;

Table A (about 100k rows and Code1 column is unique)

Code1Code2Code3
111
222444
333555666

Table B (more than 1 million rows)

Code
111
666
111

How i can get result like this:

Table B

CodeFirst_code_table_a
111111
666333
111111

For now I have:

LOAD Code1, Code2, Code3;

SQL SELECT Code1, Code2, Code3

FROM Table A

LOAD Code,

if (IsNull(Lookup('Code1','Code1',Code,'Table A')) = False(),

    Lookup('Code1','Code1',Code,'Table A'),

    if (IsNull(Lookup('Code1','Code2',Code,'Table A')) = False(),

    Lookup('Code1','Code2',Code,'Table A'),

    if (IsNull(Lookup('Code1','Code3',Code,'Table A')) = False(),

    Lookup('Code1','Code3',Code,'Table A'),

    'Empty'))) AS First_code_table_a;

SQL SELECT Code

FROM Table B

But it is really slow

Labels (1)
1 Solution

Accepted Solutions
vamsee
Specialist
Specialist

Hope I understood the requirement correct.

Try the following and see if its faster.

(1. Mapping loads are faster than lookup table. 2. Select * and Load * is faster while extracting data. )

TableA:
LOAD Code1, Code2, Code3;
SQL SELECT Code1, Code2, Code3
FROM Table A;
Code1_Map:
Mapping Load
Code1,
Code1
Resident TableA;
Code2_Map:
Mapping Load
Code2,
Code1
Resident TableA;
Code3_Map:
Mapping Load
Code3,
Code1
Resident TableA;
DROP Table A;
TableB:
LOAD *;
SQL SELECT Code
FROM Table B;

Final_TableB:
NoConcatenate
LOAD
Code,
ALT(ApplyMap('Code1_Map', Code,NULL()),ApplyMap('Code1_Map', Code,NULL()),ApplyMap('Code1_Map', Code,NULL()), 'Empty' ) as First_code_table_a
Resident TableB;
DROP Table B;

View solution in original post

5 Replies
MarcoWedel
MVP
MVP

try to explain the logic behind your example

vamsee
Specialist
Specialist

Hope I understood the requirement correct.

Try the following and see if its faster.

(1. Mapping loads are faster than lookup table. 2. Select * and Load * is faster while extracting data. )

TableA:
LOAD Code1, Code2, Code3;
SQL SELECT Code1, Code2, Code3
FROM Table A;
Code1_Map:
Mapping Load
Code1,
Code1
Resident TableA;
Code2_Map:
Mapping Load
Code2,
Code1
Resident TableA;
Code3_Map:
Mapping Load
Code3,
Code1
Resident TableA;
DROP Table A;
TableB:
LOAD *;
SQL SELECT Code
FROM Table B;

Final_TableB:
NoConcatenate
LOAD
Code,
ALT(ApplyMap('Code1_Map', Code,NULL()),ApplyMap('Code1_Map', Code,NULL()),ApplyMap('Code1_Map', Code,NULL()), 'Empty' ) as First_code_table_a
Resident TableB;
DROP Table B;

Death4Free
Contributor III
Contributor III
Author

Ok. I will try. I want to create relationship between Table A and Table B. Table A all the time changes. In Table B there could be codes from all columns from Table A. So my variant to create column in Table B with first code from Table A and then associate it.

Death4Free
Contributor III
Contributor III
Author

Thank you. I will try.

Death4Free
Contributor III
Contributor III
Author

Thank you. It help. Loading become really fast