Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
Modernize Your QlikView Deployment webinar, Nov. 3rd. REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Contributor III
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

Certified QS BA / DA Developer
1 Solution

Accepted Solutions
Highlighted
Contributor III
Contributor III

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

Certified QS BA / DA Developer

View solution in original post

11 Replies
Highlighted

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?

Highlighted
Contributor III
Contributor III

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

Certified QS BA / DA Developer
Highlighted

Would you be able to share the script

Highlighted
Contributor III
Contributor III

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);

Certified QS BA / DA Developer
Highlighted

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

Highlighted

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.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Highlighted
Contributor III
Contributor III

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

Certified QS BA / DA Developer

View solution in original post

Highlighted

Indeed.

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

Highlighted

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;