Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

adamjank
New Contributor III

[Left Join / Less Rows] Issue

Hello,

I've experienced very, very strange situation as the SQL experienced employee.
So after Left Joining two tables, I've got less rows on the output...
For many reasons it can be more rows due to duplicates etc., but it shouldn't be less rows.

What are the possible reasons and the solutions for that critical issue?

The keys are generated via Autonumber() and it has the same seed, furthermore I haven't got the NULLs on these fields.

I'll try to prepare the file and the script.

27-3-2017 16:41:31: 0030  Binary [..\XXX.qvw]

27-3-2017 16:41:51: 0031  Let vNumberOfRows = NoOfRows('FINAL')

27-3-2017 16:41:51: 0032  Trace 4877810

27-3-2017 16:41:51: 0032  4877810

27-3-2017 16:41:51: 0033  Left  JOIN(FINAL)

27-3-2017 16:41:51: 0034  LOAD Distinct * RESIDENT D_XXX

27-3-2017 16:41:51:      11 fields found: %XXX.KEY, XXX.Name 4 516 lines fetched

27-3-2017 16:41:51:      Joining/Keeping

27-3-2017 16:42:08: 0035  Drop Table D_XXX

27-3-2017 16:42:09: 0036  Let vNumberOfRows = NoOfRows('FINAL')

27-3-2017 16:42:09: 0037  Trace 4219022

27-3-2017 16:42:09: 0037  4219022

Kind Regards,
Adam

Tags (2)
1 Solution

Accepted Solutions
adamjank
New Contributor III

Re: [Left Join / Less Rows] Issue

Binary [..\XXX.qvw];

Let vNumberOfRows = NoOfRows('FINAL');

Trace $(vNumberOfRows);

Left  JOIN(FINAL)

LOAD *;

LOAD DISTINCT * RESIDENT D_XXX;

Drop Table D_XXX;

Let vNumberOfRows = NoOfRows('FINAL');

Trace $(vNumberOfRows);

Solution, so the DISTINCT does not affect the first table.

THANK YOU A LOT jontydkpi

11 Replies
MVP
MVP

Re: [Left Join / Less Rows] Issue

27-3-2017 16:41:31: 0030  Binary [..\XXX.qvw]

27-3-2017 16:41:51: 0031  Let vNumberOfRows = NoOfRows('FINAL')

27-3-2017 16:41:51: 0032  Trace 4877810

27-3-2017 16:41:51: 0032  4877810

Do you have a where statement here? 0032?

adamjank
New Contributor III

Re: [Left Join / Less Rows] Issue

It's just a plain binary load without any 'where', additional conditions.

MVP
MVP

Re: [Left Join / Less Rows] Issue

Would you be able to share the script

adamjank
New Contributor III

Re: [Left Join / Less Rows] Issue

Binary [..\XXX.qvw];

Let vNumberOfRows = NoOfRows('FINAL');

Trace $(vNumberOfRows);

Left  JOIN(FINAL)

LOAD Distinct * RESIDENT D_XXX;

Drop Table D_XXX;

Let vNumberOfRows = NoOfRows('FINAL');

Trace $(vNumberOfRows);

MVP
MVP

Re: [Left Join / Less Rows] Issue

Ya that is weird... may be pcammaert‌ can offer his expert advice here

MVP
MVP

Re: [Left Join / Less Rows] Issue

I think this is due to some quirky behaviour in the way QV handles DISTINCT. If you join with a distinct table, the DISTINCT operation propagates upward to the first table, so it de-duplicates the first table, reducing the number of rows.

To avoid this, assuming you need the DISTINCT, you may need to distinct load the second table into a resident table, and then left join the resident table to the binary loaded table.

adamjank
New Contributor III

Re: [Left Join / Less Rows] Issue

Binary [..\XXX.qvw];

Let vNumberOfRows = NoOfRows('FINAL');

Trace $(vNumberOfRows);

Left  JOIN(FINAL)

LOAD *;

LOAD DISTINCT * RESIDENT D_XXX;

Drop Table D_XXX;

Let vNumberOfRows = NoOfRows('FINAL');

Trace $(vNumberOfRows);

Solution, so the DISTINCT does not affect the first table.

THANK YOU A LOT jontydkpi

Re: [Left Join / Less Rows] Issue

Indeed.

Funny that a Preceding Load apparently also blocks the DISTINCT propagation. Should check this out.

Re: [Left Join / Less Rows] Issue

This is getting weird. In Adams last post, the DISTINCT keyword doesn't work at all, not even in the 2nd table (the one that is loaded first). How crazy can this become?

For example, how many rows do you get in the final copy of the RawData table?

RawData:

LOAD * INLINE [

Prod, Cust, Items

A, C1, 5

B, C1, 3

C, C2, 10

C, C3, 5

C, C3, 5

A, C1, 5

B, C1, 3

];

LET vNumRows =  NoOfRows('RawData');

TRACE >>>>> RawData before JOIN: $(vNumRows) rows;

LEFT JOIN (RawData) LOAD *;

LOAD DISTINCT * INLINE [

Prod, ProdName

A, Food

B, Brick

C, Chair

C, Chair

B, Brick

A, Food

];

LET vNumRows =  NoOfRows('RawData');

TRACE >>>>> RawData after JOIN: $(vNumRows) rows;