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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

problem with join

Hi Guys,

I'm having some problems with joining 2 tables.

I have one table with the folllowing data:

Table One:

OrderID, (Start with ULM.... and with JIL...)

Weight,

ProductType= 'Desktop'

Field A,

Field B,

Field C,

Field D,

Field E,

From

CustomerOrders.xls

Table Two:

Purge(OrderID,'-') as OrderID, (Orders only with ULM)

Weight

From,

Select OrderID, Weight

     Where left(OrderID,3)= 'ULM';

The second table does not contain orders that start with JIL, so therefore I filtered it to show only orders that start with 'ULM'

I want to joins these to tables. However if I do a left join (table 1), I get the weights only for the producttype 'Desktop', if I do a right join (table 2) I would only get the weights for Server and the OrderID without the all the other fields. I can't do an inner join, because that would excluse orders that start with JIL.

If I do an outer join, I would get the following results

Which makes sences ,:

OrderIDWeightProductTypeField AField BField C
Field D
Field E

ULM1234567

30 KG------
ULM1234567-Serversome valuesome valuesome valuesome valuesome value
JIL1254788910 KGDesktopsome valuesome valuesome valuesome valuesome value
JIL125478899 KGDesktopsome valuesome valuesome valuesome valuesome value
ULM123456535 KG------
ULM1234565-Serversome value-some valuesome valuesome valuesome value

Is there a way I can create the below outcome:

OrderIDWeightProductTypeField AField BField CField DField E
ULM123456730 KGServersome valuesome valuesome valuesome valuesome value
ULM123456535 KGServersome valuesome valuesome valuesome valuesome value
JIL1254788910 KGDesktopsome valuesome valuesome valuesome valuesome value

I've tried estabilsing a relationship between the OrderID from table 1 and from table 2, but that didn't solve anything.

Does any know how to solve this in the load script?

Regards,

Carter

1 Solution

Accepted Solutions
erichshiino
Partner - Master
Partner - Master

Hi,

You can create temporary fields Weight1 and Weight2 and then, on an additional step, select one of the values as a final Weight field.

The script would be more or less like this:

Table1:

Load

OrderID, (Start with ULM.... and with JIL...)

  Weight as Weight1,

ProductType= 'Desktop'

Field A,

Field B,

Field C,

Field D,

Field E,

   From

CustomerOrders.xls;

left join(  Table1)

Load

Purge(OrderID,'-') as OrderID, //(Orders only with ULM)

Weight as Weight2

;

   Select OrderID, Weight

from ....

     Where left(OrderID,3)= 'ULM';

FinalTable:

Load *,

if( isnull(Weight1), Weight2, Weight1) as Weight

resident Table1;

drop table Table1;

drop fields  Weight1, Weight2;

(it may need to correct some syntax mistakes here)

Hope this helps

Erich

View solution in original post

2 Replies
erichshiino
Partner - Master
Partner - Master

Hi,

You can create temporary fields Weight1 and Weight2 and then, on an additional step, select one of the values as a final Weight field.

The script would be more or less like this:

Table1:

Load

OrderID, (Start with ULM.... and with JIL...)

  Weight as Weight1,

ProductType= 'Desktop'

Field A,

Field B,

Field C,

Field D,

Field E,

   From

CustomerOrders.xls;

left join(  Table1)

Load

Purge(OrderID,'-') as OrderID, //(Orders only with ULM)

Weight as Weight2

;

   Select OrderID, Weight

from ....

     Where left(OrderID,3)= 'ULM';

FinalTable:

Load *,

if( isnull(Weight1), Weight2, Weight1) as Weight

resident Table1;

drop table Table1;

drop fields  Weight1, Weight2;

(it may need to correct some syntax mistakes here)

Hope this helps

Erich

Not applicable
Author

Thank you so much Erich!! That solved the problem!!