Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

Join a table with another table using subset of first table's key

Hi,

the title might be confusing but here is the idea:

I have 2 tables and I want to join both tables, but....

here is the case:

table1:

CodeDescription
101.110.255Desc1
101.100.202Desc2
101.200.301Desc3
202.110.111Desc4
202.100.200Desc5
302.300.100Desc6

table2:

CodeGroupGroupName
101.1Current Asset
101.200Fixed Asset
202.11Income
202.10Other Income
302.3

Other Income

The expected result is:

CodeDescriptionCodeGroupGroupName
101.110.255Desc1101.1Current Asset
101.100.202Desc2101.1Current Asset
101.200.301Desc3101.200Fixed Asset
202.110.111Desc4202.11Income
202.100.200Desc5202.10Other Income
302.300.100Desc6302.3Other Income

I want to show which code belong to which CodeGroup and GroupName.

Thanks for your help

1 Solution

Accepted Solutions
flipside
Valued Contributor II

Join a table with another table using subset of first table's key

Hi Reynald,

You can build an intermediate lookup table to join the two tables as this ...

Lkp:

LOAD Code, text(left(Code,5)) as Key resident Table1;

LOAD Code, text(left(Code,6)) as Key resident Table1;

LOAD Code, text(left(Code,7)) as Key resident Table1;

inner join (Lkp)

LOAD text(CodeGroup) as Key, GroupName resident Table2;

Note the text statement around the Code field as the CodeGroup values are numeric whereas the Codes are not.

flipside

4 Replies
chematos
Valued Contributor II

Re: Join a table with another table using subset of first table's key

Hi,

If that are the only data you have to join, you could create two fields in both tables with the first 5,6 characters so you will have the Keys to join the tables.

Table1:

Load *,

Left(Code,5) as %Key,

Left(Code,6) as %Key2

From TABLE1;

Left join(Table1)

Load *,

if(len(CodeGroup)=5,Left(CodeGroup,5)) as %Key

From TABLE2;

Left join(Table1)

Load *,

if(len(CodeGroup)>5,Left(CodeGroup,6)) as %Key2

From TABLE2;


I ' ve don't try this, hope this helps

flipside
Valued Contributor II

Join a table with another table using subset of first table's key

Hi Reynald,

You can build an intermediate lookup table to join the two tables as this ...

Lkp:

LOAD Code, text(left(Code,5)) as Key resident Table1;

LOAD Code, text(left(Code,6)) as Key resident Table1;

LOAD Code, text(left(Code,7)) as Key resident Table1;

inner join (Lkp)

LOAD text(CodeGroup) as Key, GroupName resident Table2;

Note the text statement around the Code field as the CodeGroup values are numeric whereas the Codes are not.

flipside

Not applicable

Join a table with another table using subset of first table's key

Hi, thanks for ur help btw.

I havent tried any of the solution

but once Ive tried, i will inform my progress.

Thanks anyway

Not applicable

Join a table with another table using subset of first table's key

Thanks flipside,

Your solution worked like charm.

Thank you so much.

Community Browser